Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 495 Accepted Submission(s): 162
Problem Description
Chiaki often participates in international competitive programming contests. The time zone becomes a big problem.
Given a time in Beijing time (UTC +8), Chiaki would like to know the time in another time zone s.
Given a time in Beijing time (UTC +8), Chiaki would like to know the time in another time zone s.
Input
There are multiple test cases. The first line of input contains an integer 9).
Output
For each test, output the time in the format of m (24-hour clock).
Sample Input
3
11 11 UTC+8
11 12 UTC+9
11 23 UTC+0
Sample Output
11:11
12:12
03:23
Source
题意:北京标准时间是UTC+8
现在给出标准的北京时间和别的地方的时区
要求别的地方的当前时间
模拟题:
注意细节:1 会有浮点误差,所以把小数位拿出来单独计算
2注意当h小于0的时候,要转换成前一天的时间
3是UTC-xy时,可以当成是当前时间+16-xy的时间
代码如下
#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 */