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

过这道题过的好纠结啊

Posted by 1805180411 at 2011-11-09 15:12:55
原来还要考虑那么多的细节啊;还行,总算过了;
#include<iostream>
#include<memory>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iomanip>
using namespace std;

int main()
{
	char str[20],ch[20];
	double dou = 0;
	int i;

	double speed1 = 0;
	int time0,time,len;
	gets(str);
	len = strlen(str);
    if(len == 8)
		cout<<str<<" 0.00 km"<<endl;
	else
	{
		time0 = ((str[0]-'0')*10+(str[1]-'0')*3600 + ((str[3]-'0')*10 + (str[4] - '0'))*60 + ((str[6]-'0')*10 + (str[7] -'0')));
        for(i = 9;i < len;i++)
		{
			speed1 = speed1*10 + (str[i]-'0');

		}
	}
	while(gets(str))
	{
		len = strlen(str);
		if(len == 8)
		{

			time = ((str[0]-'0')*10+(str[1]-'0')*3600 + ((str[3]-'0')*10 + (str[4] - '0'))*60 + ((str[6]-'0')*10 + (str[7] -'0')));
	        dou += speed1*(time - time0)/3600;
		
			cout<<str<<" "<<setiosflags(ios::fixed)<<setprecision(2)<<dou<<" km"<<endl;
			time0 = time;
		}
		else
		{
            time = ((str[0]-'0')*10+(str[1]-'0')*3600 + ((str[3]-'0')*10 + (str[4] - '0'))*60 + ((str[6]-'0')*10 + (str[7] -'0')));
			dou += speed1*(time - time0)/3600;
			speed1 = 0;
            for(i = 9;i < len;i++)
			{
			    speed1 = speed1*10 + (str[i]-'0');

			}
			time0 = time;

		}
	}
	//system("pause");
	return 0;

}

Followed by:

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