hdu6556 The World(水题)

题目链接:hdu6556

题意:给定两个城市名称和第一个城市的时间,要你计算出第二个城市的时间。

思路:先把时间转换成24小时制,然后在计算出第二个城市的时间,最后在进行判断在今天或者昨天或则明天。

code:

#include<bits/stdc++.h>
using namespace std;
int main() {
	int t;
	cin >> t;
	unordered_map<string, int> mmid;
	mmid["London"] = 0;
	mmid["Beijing"] = 8;
	mmid["Washington"] = -5;
	mmid["Moscow"] = 3;
	int cases = 0;
	while (t--) {

		int h, m;
		char ch;
		string str;
		cin >> h >> ch >> m >> str;
		string s1, s2;
		cin >> s1 >> s2;
		if (h == 12)
			h = 0;
		if (str == "PM")
			h += 12;
		int ans = h - mmid[s1];
		ans += mmid[s2];
		string day = "Today", res = str;
		if (ans >= 24) {

			day = "Tomorrow";
		}
		else if (ans >= 0 && ans < 24) {
			day = "Today";
		}
		else if (ans < 0) {
			day = "Yesterday";
		}

		printf("Case %d: ", ++cases);
		ans = ans + 24;
		ans %= 24;
		if (ans < 12)
			res = "AM";
		else
			res = "PM";
		if (ans == 0)
			ans = 12;
		else if (ans > 12)
			ans -= 12;
		printf("%s %d:%02d %s\n", day.c_str(), ans, m, res.c_str());

	}
	return 0;
}
发布了50 篇原创文章 · 获赞 52 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_43058685/article/details/104126483