Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 495 Accepted Submission(s): 162
Given a time in Beijing time (UTC +8), Chiaki would like to know the time in another time zone s.
The first line contains two integers a, b (0≤a≤23,0≤b≤59) and a string s in the format of "UTC+X'', "UTC-X'', "UTC+X.Y'', or "UTC-X.Y'' (0≤X,X.Y≤14,0≤Y≤9).
#include <cstdio> #include <algorithm> #include <iostream> #include <cstring> using namespace std; int main(){ int T; scanf("%d",&T); while(T--){ int hh,mm; scanf("%d%d",&hh,&mm); char str[100]; scanf("%s",str); int len=strlen(str); int flag=0; int th=0; int tm=0; if(str[3]=='+'){ for(int i=4;i<len;i++){ if(str[i]=='.'){ flag=i; break; } th=th*10+str[i]-'0'; } if(flag!=0){ tm=str[flag+1]-'0'; mm+=((tm*60)/10); if(mm>=60){ mm-=60; th++; } } hh+=(th-8); if(hh>=24) hh-=24; if(hh<0) hh+=24; if(hh<10) cout<<"0"; //前导零 cout<<hh<<":"; if(mm<10) cout<<"0"; cout<<mm<<endl; }else { int tth=0; int th=16; for(int i=4;i<len;i++){ if(str[i]=='.'){ flag=i; break; } tth=tth*10+str[i]-'0'; } th-=tth; if(flag!=0){ tm=str[flag+1]-'0'; mm-=((tm*60)/10); if(mm<0){ mm+=60; th--; } } hh+=th; if(hh>=24) hh-=24; if(hh<10) printf("0"); printf("%d:",hh); if(mm<10) printf("0"); printf("%d\n",mm); } } return 0; } /* 01 14 UTC+2.6 19:50 */