- /*
- 第一行的速度可能为0,故初始速度要为0
- */
- #include<iostream>
- usingnamespacestd;
- intmain()
- {
- freopen("in.txt","r",stdin);
- inth,m,s,k(0);
- intpres(0),nows,time;
- doublesum=0.0;
- charc;
- 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.2lfkm\n",sum);
- }
- pres=s+m*60+h*60*60;
- }
- return0;
- }
2501 Average Speed
最新推荐文章于 2022-02-25 20:00:37 发布
本文介绍了一个使用C++实现的程序,该程序能够读取24小时制的时间记录,并计算出不同时间段内的平均速度。特别注意的是如何处理从24小时重置到0小时的情况。
927

被折叠的 条评论
为什么被折叠?



