您的位置:首页 > 其它

2501 Average Speed

2008-11-10 17:36 113 查看
/*

第一行的速度可能为0,故初始速度要为0

*/

#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小时
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: