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
题意:
给一个UTC+8时区的时间,求新时区的时间。
思路:
处理字符串将TUC后边的时区数值提取出来,和TUC+8时区做差,
例如UTC-2与UTC+8 相差-10个时区,如果UTC+8时区的时间为12:25,
则UTC-2时区的时间为02:25。
当时不明白负时区如何算,试尽了所有可能,全错了.....
吐槽一下:题目的时区划分不符合地理常识
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int h,m;
char str[20];
int getTime(){// 处理 UTC后的数值,并转化成分钟
int flag=0;
if(str[3]=='+') flag=1;
else flag=-1;
int a=0,b=0;
int i=4,len=strlen(str);
for(i=4;i<len;i++){
if(str[i]=='.') break;
a=a*10+(str[i]-'0');
}
if(str[i]=='.') b=str[i+1]-'0';
int c=a*60+b*6;
return flag*c-8*60; //返回与UTC+8 相差的时间
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%s",&h,&m,str);
int t=getTime();
t=(h*60+m+60*24+t)%(60*24);
printf("%02d:%02d\n",t/60,t%60);
}
return 0;
}