Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2049 Accepted Submission(s): 636
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
这题看起来不难,但是精度问题挺烦人的.
1 #include <iostream> 2 using namespace std; 3 int n; 4 int main(){ 5 scanf("%d",&n); 6 int x,y; 7 double z; 8 char s[4]; 9 while(n--){ 10 scanf("%d%d%c%c%c%c%lf",&x,&y,&s[0],&s[1],&s[2],&s[3],&z); 11 if(s[3]=='-'){ 12 z = -z; 13 } 14 double k = (z-8.0)*60.0; 15 k += k>0?0.5:-0.5; 16 int ans = (int)(k); 17 ans +=(x*60+y); 18 ans = (ans+1440)%1440; 19 int xn = (ans/60)%24; 20 int yn = ans%60; 21 printf("%02d:%02d\n",xn,yn); 22 } 23 return 0; 24 }