| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
贴个AC的代码//2501//如果此题询问的时间不是递增的,那要用数组存储变速的时间
#include<iostream>
using namespace std;
int main()
{
int h,m,s,th=0,tm=0,ts=0;
char c;
double speed=0,distance=0,distance0=0;
while(cin>>h>>c>>m>>c>>s)//要注意第一次输入可能没速度的
{
if((c=getchar())==' ')
{
distance0=distance0+(((h-th)*60*60+(m-tm)*60+(s-ts))*(speed/3600.0));//不要忘了distance0
cin>>speed;//输入肯定要在计算distance0之后
th=h;
tm=m;
ts=s;
}
else
{
distance=distance0+(((h-th)*60*60+(m-tm)*60+(s-ts))*(speed/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("%.2lf km\n",distance);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator