百度之星之D:共同狂欢

D:共同狂欢

时间限制:

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

样例输出

24

0

15

12

【答案】

#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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

铭毅天下

和你一起,死磕Elastic!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值