UVA 10281 - Average Speed

UVA Sep 1, 2020

Problem PDF

Solution:

#include<stdio.h>
int main()
{
    double h1,m1,s1,h,m,s,hour,v,dist=0,left_hour=0;
    char a[200];
    while(gets(a))
    {
        sscanf(a,"%lf:%lf:%lf",&h1,&m1,&s1);
        hour=h1*60+m1+s1/60;
        if(a[8]=='\0')
        {
            dist=dist+(v*(hour-left_hour))/60;
            printf("%s %.2lf km\n",a,dist);
        }
        else
        {
            dist=dist+(v*(hour-left_hour))/60;
            sscanf(a+8,"%lf",&v);
        }
        left_hour=hour;
    }
    return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/10281/10281.cpp

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.