| ||||||||||
| 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 | |||||||||
真是惭愧啊,这题也错了好几次呀。不过过百题了纪念一下吧。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator