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

Post by tzupengwang » Wed Aug 15, 2012 7:27 pm

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
Location: BUBT,Dhaka, Bangladesh
Contact:

Re: 10281 - Average Speed

Post by alimbubt » Tue Jan 01, 2013 5:53 pm

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

Post by techbd123 » Sun Aug 18, 2013 1:31 am

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

Post by brianfry713 » Mon Aug 19, 2013 10:08 pm

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

Post by techbd123 » Wed Aug 21, 2013 12:29 am

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

Post by brianfry713 » Tue Oct 08, 2013 12:35 am

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

Post by triplemzim » Wed Dec 04, 2013 11:28 am

Thanks brianfry... :)

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

Re: 10281 - Average Speed

Post by sadmansobhan » Sun Dec 29, 2013 6:09 pm

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

Post by brianfry713 » Wed Jan 15, 2014 1:21 am

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

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

Re: 10281 - Average Speed

Post by uDebug » Tue May 13, 2014 12:34 pm

brianfry713 and alimbubt,

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

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 102 (10200-10299)”