题目连接:http://poj.org/submit?problem_id=2501
题目解析:这题没做出来,是因为时间格式的转换忘记了,其次是速度有的时候有,有的时候没有,不知道怎么解决,不过这题让我收获颇大
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<cstdlib>
using namespace std;
int cal(int h,int m,int s){
return h*3600+m*60+s;
}
int main(){
int h,m,s;
double speed=0;
double ans=0;
int last=0;
while (scanf("%d:%d:%d",&h,&m,&s)!=EOF){
char ch=getchar();
if (ch==' '){
int a;
scanf("%d",&a);
int now=cal(h,m,s);
ans+=(now-last)*speed;
last=now;
speed=a/3.6;
}
else
printf("%02d:%02d:%02d %.2f km\n",h,m,s,(ans+(cal(h,m,s)-last)*speed)/1000);
}
return 0;
}