将时间转换为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;
}