2501 Average Speed
来源:互联网 发布:淘宝店铺名称设计 编辑:程序博客网 时间:2024/06/09 17:33
- #include<iostream>
- using namespace std;
- int main()
- {
- freopen("in.txt","r",stdin);
- int h,m,s,k(0);
- int pres(0),nows,time;
- double sum=0.0;
- char c;
- while(scanf("%d%c%d%c%d",&h,&c,&m,&c,&s)!=EOF)
- {
- c=getchar();
- if(h==24)
- h=0;
- if(c!='/n')
- {
-
- if(pres!=0)
- {
- nows=s+m*60+h*60*60;
- time=nows-pres;
- sum+=time*k/3600.0;
- }
- cin>>k;
- }
- else
- {
-
- nows=s+m*60+h*60*60;
- time=nows-pres;
- if(k!=0)
- sum+=time*k/3600.0;
- if(h<10)
- cout<<0<<h<<":";
- else
- cout<<h<<":";
- if(m<10)
- cout<<0<<m<<":";
- else
- cout<<m<<":";
- if(s<10)
- cout<<0<<s<<" ";
- else
- cout<<s<<" ";
- printf("%0.2lf km/n",sum);
- }
-
- pres=s+m*60+h*60*60;
-
- }
- return 0;
- }
关键是输出格式的处理,还又要注意 24小时变为0小时