HDU-6556 The World(模拟、24小时制)

将时间转换为24小时制,12:00AM为 0:00,12:00PM为12:00;
求出时差,计算出更新后的时间,
然后判断更新后的时间小于0则为昨天,大于等于24则为明天;

#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
char zt[2][5] = {"AM", "PM"};
char time[3][20] = {"Yesterday", "Today", "Tomorrow"};
map<char, int> mp;
int main()
{
	int t, cnt = 1;;
	scanf("%d", &t);
	mp['B'] = 8;
	mp['W'] = -5;
	mp['L'] = 0;
	mp['M'] = 3;
	while(t--){
		int h, m;
		scanf("%d:%d", &h, &m);
		getchar();
		char tmp[20], s1[20], s2[20];
		scanf("%s", tmp);
		scanf("%s", s1);
		scanf("%s", s2);
		int cmp1 = mp[s1[0]], cmp2 = mp[s2[0]];
		int t = cmp2 - cmp1, t1 = 1, t2, h1;
		if(!strcmp("AM", tmp)){
			h1 = h % 12;
		}
		else{
			h1 = 12 + (h % 12);
		}
		if(h1 + t < 0){
			--t1;
			h1 = 24 + (h1 + t);
		}
		else if(h1 + t < 24){
			h1 += t;
		}
		else{
			++t1;
			h1 = (h1 + t) % 24;
		}
		if(h1 >= 0 && h1 <= 11){
			t2 = 0;
		}
		else{
			t2 = 1;
		}
		h1 %= 12;
		if(h1 == 0){
			h1 = 12;
		}
		printf("Case %d: %s %d:%02d %s\n", cnt, time[t1], h1, m, zt[t2]);
		++cnt;
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值