Uva 10281 Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double previous_time = 0, current_time = 0, hour = 0, minute = 0, second = 0, distance = 0, speed = 0;
    char s[100];
    cout << showpoint;
    cout << fixed;
    cout << setprecision(2);
    while(cin >> s)
    {
        sscanf(s, "%lf:%lf:%lf", &hour, &minute, &second);

        current_time = (hour*3600.0)+(minute*60.0)+second;

        distance = distance + ((current_time - previous_time)*(speed/3600.0));

        char ch = getchar();

        if(ch == ' ')
            cin >> speed;
        else if(ch == '\n')
            cout << s << " " << distance << " km" << endl;

        previous_time = current_time;
    }

    return 0;
}

Comments