时间限制:
1000ms
内存限制:
131072kB
描述
百度2005年8月5日上市时,在北京和纳斯达克的同学们每一个小时整点时就会通一次电话,对一下表,确认一切相关活动都精确同步。但是要注意,在两边的同学位于不同的时区,在夏时制时,两地时差12小时,因此,每次对表都需要做一下时区转换。你来帮我们完成这个有点麻烦的工作吧。
输入
输入的第一行包括一个整数T(T ≤ 30),表示测试数据的组数;接下去的T行每行包括一个时间,表示两地中的一个地方同学报出的整点的时间,表示成“H:M”的形式,其中H是小时(0 ≤H < 24,且当H小于10的时候可以表示成1位或者2位的形式)、M是分钟(0 ≤ M < 60,且当M小于10的时候可以表示成1位或者2位)。
输出
每个测试数据输出一行,当是整点对时时,输出时区转换后的小时结果;当不是整点对时时,输出0。
样例输入
4
12:00
01:01
3:00
00:00
AI 代码解读
样例输出
24 0 15 12
AI 代码解读
【答案】
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main(void)
{
int iGroups;
const char* pStrSubLeft = new char[10];
const char* pStrSubRight = new char[10];
string strSubLeft;
string strSubRight;
int iInterVal = 0;
int iLen = 0;
int iMinute = 0;
int iHour = 0;
int iResult = 0;
cin >> iGroups;
if(iGroups > 30)
{
cout << "Error!" << endl;
return -1;
}
string strTimeArr[30];
for( int i = 0; i < iGroups; i++)
{
cin >> strTimeArr[i];
iInterVal = strTimeArr[i].find(':');
iLen = strTimeArr[i].length();
strSubRight = strTimeArr[i].substr(iInterVal+1,iLen);
pStrSubRight = strSubRight.c_str();
iMinute = atoi(pStrSubRight);
strSubLeft = strTimeArr[i].substr(0,iInterVal);
pStrSubLeft = strSubLeft.c_str();
iHour = atoi(pStrSubLeft);
if(iHour < 0 || iHour >= 24)
{
cout << "Error!" << endl;
return -1;
}
if(iMinute < 0 || iMinute >= 60)
{
cout << "Error!" << endl;
return -1;
}
if(iMinute != 0)
{
iResult = 0;
}
else
{
if(iHour >= 0 && iHour <= 12)
{
iResult = iHour + 12;
}
else if(iHour > 12 && iHour <= 24)
{
iResult = iHour - 12;
}
}
cout << iResult << endl;
}
cout << endl;
return 0;
}
AI 代码解读
作者:铭毅天下
原文:https://blog.csdn.net/laoyang360/article/details/7621101
版权声明:本文为博主原创文章,转载请附上博文链接!