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

为什么OLE啊啊啊???????????郁闷

Posted by wangyaoxuan at 2010-03-24 11:25:03 on Problem 2501
#include <iostream>
using namespace std;

void tran1(char line[], int &h1, int &m1, int &s1, float &v)
{
	int i, m;
	h1 = (line[0]-48)*10 + line[1]-48;
	m1 = (line[3]-48)*10 + line[4]-48;
	s1 = (line[6]-48)*10 + line[7]-48;
	m = 1;
	v = 0;
	for(i=strlen(line)-1; line[i]!=' '; i--)
	{
		v += (line[i]-48)*m;
		m *= 10;
	}
}

void tran2(char line[], int &h1, int &m1, int &s1)
{
	h1 = (line[0]-48)*10 + line[1]-48;
	m1 = (line[3]-48)*10 + line[4]-48;
	s1 = (line[6]-48)*10 + line[7]-48;
}

int main()
{
	char line[20];
	int h1, m1, s1;
	int h2, m2, s2;
	float v1=0, v2=0, dis, dt;
	int flag;

	gets(line);
	tran1(line, h1, m1, s1, v1);
	dis = 0;
	while(1)
	{
		dt = 0;
		flag = 0;
		if(line[8] == ' ')
		{
			tran1(line, h2, m2, s2, v2);
			if(s2<s1)
			{
				s2 += 60;
				flag = -1;
				if(m2+flag<m1)
				{
					m2 += flag + 60;
					flag = -1;
				}
				else
					flag = 0;
				h2 += flag;
			}
			else if(s2>s1 && m2<m1)
			{
				h2--;
				m2 +=60;
			}
			dt = (h2-h1)*3600 + (m2-m1)*60 + s2-s1;
			dt /= 3600;
			dis += dt*v1;
			v1 = v2;
			h1 = h2;
			m1 = m2;
			s1 = s2;
		}
		else
		{
			tran2(line, h2, m2, s2);
			if(s2<s1)
			{
				s2 += 60;
				flag = -1;
				if(m2+flag<m1)
				{
					m2 += flag + 60;
					flag = -1;
				}
				else
					flag = 0;
				h2 += flag;
			}
			else if(s2>s1 && m2<m1)
			{
				h2--;
				m2 +=60;
			}
			dt = (h2-h1)*3600 + (m2-m1)*60 + s2-s1;
			dt /= 3600;
			dis += dt*v1;
			cout.setf(ios::fixed);/////
			cout.precision(2);
			cout<<line<<" "<<dis<<" km"<<endl;
			h1 = h2;
			m1 = m2;
			s1 = s2;
		}
		
		if((gets(line))==EOF)
			break;
	}
	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