hdu6556 The World(水题)

编程入门 行业动态 更新时间:2024-10-28 07:20:15

hdu6556 The <a href=https://www.elefans.com/category/jswz/34/1769196.html style=World(水题)"/>

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";elseres = "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;
}

更多推荐

hdu6556 The World(水题)

本文发布于:2023-07-28 20:49:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1305179.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:World   水题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!