2018HDU多校聯賽第一場Time Zone
Time Zone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 997 Accepted Submission(s): 328
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
題目大意:給你時間,讓你求出在經過多少個時區後的時間,
思路:沒有思路,就是直接算
程式碼:
#include<map> #include<stack> #include<queue> #include<cstdio> #include<string> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; const int N=4e6+10; char time[10]; int a[N],b[N]; int main() { int test; scanf("%d",&test); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); while(test--) { int i,j,l,k=0,x=0; int hour,minute; double y=0.0; scanf("%d%d",&hour,&minute); scanf("%s",time); l=strlen(time); for(i=4; i<l; i++) { if(time[i]=='.') { k=i; break; } else x=x*10+(time[i]-'0'); } if(k!=0) { for(i=k+1; i<l; i++) { y=0.1*y+(time[i]-'0'); } } y*=0.1; y*=60; if(time[3]=='+') { x-=8; hour+=x; minute+=y; if(minute>=60) { minute-=60; hour+=1; } if(hour<0) { hour+=24; } } else if(time[3]=='-') { x+=8; hour-=x; minute-=(int)y; if(minute<0) { hour-=1; minute+=60; } if(minute>=60) { minute-=60; hour+=1; } if(hour<0) { hour+=24; } } if(hour>=24) { hour-=24; } hour>9?printf("%d:",hour):printf("0%d:",hour); minute>9?printf("%d\n",minute):printf("0%d\n",minute); } return 0; }