题目链接: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;
}