Time Zone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 282 Accepted Submission(s): 94
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
解析:都换算成分钟,就比较容易算了
#include<bits/stdc++.h>
using namespace std;
#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
int main()
{
int t;scanf("%d",&t);
while(t--)
{
char s[40];
int x,y;scanf( "%d%d%s" ,&x,&y,s);
int a=0,b=0;
int len=strlen(s);
for(int i=4;i<len;i++)
{
if(s[i]=='.')break;
a=a*10+s[i]-'0';
}
int f=1;
for(int i=0;i<len;i++)
if( s[i]=='.') f=0;
if( f==0 ) b=s[len-1]-'0';
int t1=x*60+y,ans;
if( s[3]=='+'&&a>=8)
ans=t1+(a-8)*60+b*6;
else if( s[3]=='+'&&a<8 )
ans=t1-(8-a)*60+b*6;
else
ans=t1-(8+a)*60-b*6;
ans=(ans+24*60)%(24*60);
printf("%02d:%02d\n",ans/60,ans%60);
}
return 0;
}