Problem A: Problem A: Average Speed
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 54 Solved: 24
[ Submit][ Status][ Web Board]
Description
Problem A: Average Speed
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.
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.
For each query in standard input, you should print a line giving the time and the distance travelled, in the format below.
Input
Output
Sample Input
Sample Output
#include<iostream>
#include<string>
#include<map>
#include<cstring>
#include<cstdio>
using namespace std;
int facs(int h,int m,int s)
{
return h*3600+m*60+s;
}
int main()
{
int n,m,i,j,d,p,q,v;
int now=0,last=0;
double k=0,sum,sum1;
char c;
while(~scanf("%d:%d:%d",&p,&q,&v))
{
c=getchar();
if(c==' ')
{
scanf("%d",&d);
now=facs(p,q,v);
sum+=(now-last)*k;//这个距离是表示上一个改变速度的时刻到现在改变速度的时刻走了多远。
k=d/3.6;//这个时候如果是100公里每小时那就是100000/3600,表示1s多少米
last=now;//记录上一个时刻
}
else
{
sum1=((facs(p,q,v)-last)*k+sum)/1000;
printf("%02d:%02d:%02d %.2f km\n",p,q,v,sum1);
}
}
return 0;
}