Time Zone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 307 Accepted Submission(s): 102
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
2018 Multi-University Training Contest 1
Recommend
liuyiding | We have carefully selected several similar problems for you: 6308 6307 6306 6305 6304
Pay attention:
注意精度损失。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = 1e6+10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int N = 1010;
int t,n;
int h,m;
char s[10];
int main(){
scanf("%d",&t);
while(t--){
memset(s,0,sizeof(s));
int time = 0;
bool check = true;
scanf("%d %d %s",&h,&m,s);
if(s[3]=='-') check = false;
int id = -1;
int len = strlen(s);
for(int i=4;i<len;i++){
if(s[i]!='.'){
time = time*10+(int)(s[i]-'0');
}
else{
id = i;break;
}
}
int temp = 0;
if(id != -1){
for(int i=id+1;i<len;i++){
temp = temp*10+(int)(s[i]-'0');
}
}
int hh = (int)(time);
int mm = temp*6;
if(!check){
hh += 8;
h = h-hh;
m = m-mm;
}
else{
hh -= 8;
h = h+hh;
m = m+(int)mm;
}
if(m<0){
h--;m+=60;
}
else if(m>=60){
h++;m-=60;
}
if(h>=24) h-=24;
if(h<0) h+=24;
printf("%02d:%02d\n",h,m);
}
return 0;
}
/*
10
11 11 UTC+8.5
10 10 UTC-8.5
10 10 UTC+8.5
*/