## 10281 - Average Speed

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

tzupengwang
New poster
Posts: 36
Joined: Fri Dec 02, 2011 1:30 pm
Location: Kaohsiung, Taiwan

### Re: 10281 - Average Speed

I get AC now~
But it's not a precision problem
it's a input problem with the first line
it's not necessary to have a "speed" input at the end of the first line
Thank you very for your help !!!
I really appreciate it

alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Contact:

### Re: 10281 - Average Speed

Critical Input

Input:

Code: Select all

``````00:00:01 100
00:15:01
00:30:01
01:00:01 0
03:00:01
03:00:05 140``````
Output:

Code: Select all

``````00:15:01 25.00 km
00:30:01 50.00 km
03:00:01 100.00 km``````
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/

techbd123
New poster
Posts: 14
Joined: Tue Aug 06, 2013 3:42 pm

### Re: 10281 - Average Speed

Code: Select all

``Removed the code after getting AC``
Last edited by techbd123 on Wed Aug 21, 2013 12:31 am, edited 2 times in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10281 - Average Speed

tzupengwang wrote:I get AC now~
But it's not a precision problem
it's a input problem with the first line
it's not necessary to have a "speed" input at the end of the first line
Thank you very for your help !!!
I really appreciate it
Check input and AC output for thousands of problems on uDebug!

techbd123
New poster
Posts: 14
Joined: Tue Aug 06, 2013 3:42 pm

### Re: 10281 - Average Speed

Thanks to Guru! Brianfry

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10281 - Average Speed

Input:

Code: Select all

``````00:15:01
``````
AC output:

Code: Select all

``````00:15:01 0.00 km
``````
Check input and AC output for thousands of problems on uDebug!

triplemzim
New poster
Posts: 48
Joined: Sat Apr 06, 2013 6:02 pm

### Re: 10281 - Average Speed

Thanks brianfry...

New poster
Posts: 16
Joined: Thu Oct 10, 2013 8:06 am

### Re: 10281 - Average Speed

Code: Select all

``````#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{

int speed,first,temp,second,len,i;
float total=0;
char time[20];
while(gets(time))
{
len=strlen(time);
if(len<9)
{
second=((time[0]-'0')*10+time[1]-'0')*3600+((time[3]-'0')*10+time[4]-'0')*60+(time[6]-'0')*10+time[7]-'0';
total+=((second-first)*speed)/3600;
printf("%s %.2f km\n", time, total);
first=second;
}
else
{
second=((time[0]-'0')*10+time[1]-'0')*3600+((time[3]-'0')*10+time[4]-'0')*60+(time[6]-'0')*10+time[7]-'0';
total+=((second-first)*speed)/3600;
speed=0;
temp=len-1;
i=1;
while(temp>8)
{
speed+=(time[temp]-'0')*i;
i=i*10;
temp--;
}
first=second;
}

}
return 0;
}
``````
i am getting wrong answer. but my code give sample output. please help me.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10281 - Average Speed

Try using double instead of float
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 10281 - Average Speed

brianfry713 and alimbubt,

Thanks for the great test cases.
Check input and AC output for over 7,500 problems on uDebug!