Time Zone
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.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case: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).
Output
For each test, output the time in the format of hh:mm (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#include #include #include 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 =60){ mm-=60; th++; } } hh+=(th-8); if(hh>=24) hh-=24; if(hh<0) hh+=24; if(hh<10) cout<<"0"; //前导零 cout< <<":"; if(mm<10) cout<<"0"; cout< < =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.619:50*/