[Title Description]: Give us time and speed, and let us find the distance from leaving
[Analysis]: The question was not clearly displayed at the beginning, so I understood it after looking at other people's questions.
Summary of this question:
1. Time Input Method: scanf ("% d: % d", & H, & M, & S). Pay attention to accumulation!
2. for space input control, char CH = getchar () is used. It also serves as a condition for determining whether to output an identifier.
3. accumulate more methods for similar questions.
Code reference.
// 144K 0Ms#include<iostream>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,((cal(h,m,s)-last)*speed+ans)/1000); } return 0;}
Poj 2501 average speed (a good question)