题目:Time Zone
思路:模拟。
代码:
#include<bits/stdc++.h>
using namespace std;int X,Y;
char s[15];
int opr,h,m;void init() {opr=h=m=0;opr=(s[3]=='+'?1:-1);if(s[5]=='.') {h=s[4]-'0';m=s[6]-'0';} else if(s[6]=='.') {h=(s[4]-'0')*10+s[5]-'0';m=s[7]-'0';} else {if(strlen(s)==5) {h=s[4]-'0';} else {h=(s[4]-'0')*10+s[5]-'0';}}if(opr>0) {h-=8;if(h<0) h+=24;} else if(opr<0) {h+=8;h%=24;}
}int main() {int T;scanf("%d",&T);while(T--) {for(int i=0;i<10;i++) s[i]=0;scanf("%d%d%s",&X,&Y,s);init();if(opr==1) {X+=h,Y+=m*6;X+=Y/60;Y%=60;X%=24;} else {X-=h,Y-=m*6;if(Y<0) Y+=60,X--;if(X<0) X+=24;}if(X<10) printf("0%d:",X);else printf("%d:",X);if(Y<10) printf("0%d\n",Y);else printf("%d\n",Y);}return 0;
}