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 Emember at 2008-12-30 22:49:15 on Problem 2840 and last updated at 2008-12-30 22:49:55
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
	int n;
	int h,m;
	string hh,mm;
	string str;
	cin >> n;
	int len;
	while (n--)
	{
		cin >> str;
		len = str.find_first_of(':');
		hh = str.substr(0,len);
		mm = str.substr(len+1,str.length() - len - 1);

		if (hh.length() == 2)
		{
			h = (hh[0] - '0')*10 + (hh[1] - '0');
		}
		else
		{
			h = hh[0] - '0';
		}
		if ((mm.length() == 2 && mm == "00")||mm.length() == 1 && mm == "0")
		{
			m = 0;
		}
		else
		{
			m = 1;
		}
		if (m == 0 && h != 12)
		{
			cout << (12 + h)%24 << endl;
		}
		else if (h == 12)
		{
			cout << "24" << endl;
		}
		else
		{
			cout <<  "0" <<endl;
		}
	}
	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