Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4994   Accepted: 2245

Description

You have bought a car in order to drive from Waterloo to a big city. The odometer on their car is broken, so you cannot measure distance. But the speedometer and cruise control both work, so the car can maintain a constant speed which can be adjusted from time to time in response to speed limits, traffic jams, and border queues. You have a stopwatch and note the elapsed time every time the speed changes. From time to time you wonder, "how far have I come?". To solve this problem you must write a program to run on your laptop computer in the passenger seat.

Input

Standard input contains several lines of input: Each speed change is indicated by a line specifying the elapsed time since the beginning of the trip (hh:mm:ss), followed by the new speed in km/h. Each query is indicated by a line containing the elapsed time. At the outset of the trip the car is stationary. Elapsed times are given in non-decreasing order and there is at most one speed change at any given time.

Output

For each query in standard input, you should print a line giving the time and the distance travelled, in the format below.

Sample Input

00:00:01 100
00:15:01
00:30:01
01:00:01 50
03:00:01
03:00:05 140

Sample Output

00:15:01 25.00 km
00:30:01 50.00 km
03:00:01 200.00 km

 

 

有趣的一题~

【题意】:给出时间和速度,求距离

总结:

1、时间的输入方法:scanf("%d:%d:%d",&h,&m,&s),注意积累!

2、关于空格的的输入控制使用char ch = getchar(),同时它还作为了本题的一个是否输出的标识控制的条件

3、时间的输出方法:printf("%02d:%02d:%02d...

#include<iostream>
#include<stdio.h>
using namespace std;
int cal(int h,int k,int m)
{
    return h*3600+k*60+m;
}
int main()
{
    int h,k,m;
    double v=0;
    double ans=0;
    int pre=0;
    while(scanf("%d:%d:%d",&h,&k,&m)!=EOF)
    {
        char ch=getchar();
        if(ch==' ')
        {
            int a;
            scanf("%d",&a);
            int now=cal(h,k,m);
            ans+=(now-pre)*v;
            pre=now;
            v=a/3.6;
        }
        else
        {
             printf("%02d:%02d:%02d %.2f km\n",h,k,m,(ans+(cal(h,k,m)-pre)*v)/1000);
        }
    }
    return 0;
}