Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个AC的代码

Posted by scut_hcy at 2013-01-29 17:37:27 on Problem 2501
//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:
  • +1 (517) 3Dnn 2013-04-15 21:43:25

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator