标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4842 | Accepted: 2168 |
Description
Input
Output
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
Source
1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 #include<string> 5 #include<algorithm> 6 #include<iostream> 7 #include<stack> 8 using namespace std; 9 double trans(string s){ 10 return ((s[0]-‘0‘)*10+s[1]-‘0‘)*3600+((s[3]-‘0‘)*10+s[4]-‘0‘)*60+(s[6]-‘0‘)*10+s[7]-‘0‘; 11 } 12 int main(){ 13 string s; 14 double nowspeed=0,nowtime=0,speed,time,havdrive=0; 15 while(cin>>s){ 16 time=trans(s); 17 if(getchar()==‘ ‘){//速度更新,已行驶的路程更新,基准时间更新 18 cin>>speed; 19 havdrive+=(time-nowtime)/3600*nowspeed; 20 nowtime=time; 21 nowspeed=speed; 22 } 23 else{ 24 cout<<s; 25 printf(" %.2f km\n",havdrive+(time-nowtime)/3600*nowspeed);//写成printf(" %.2f km\n",havdrive+(time-nowtime)/3600*nowspeed)就错了!! 26 } 27 } 28 return 0; 29 }
标签:
原文地址:http://www.cnblogs.com/Deribs4/p/4374456.html