Time Zone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 895 Accepted Submission(s): 296
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
題意:
這就是說給你一個時間HH:MM表示,然後讓你一北京衛時間時區,給你一個新時區,讓你計算新時區的時間,就是一道模擬題,注意一下正負14時區,正負0時區,還有就是,雖然是28時區,但是用的是24小時制,也就是在24時是0時。
算法:
純模擬,就是注意一些細節情況就行了。也不是太難的模擬題。
代碼:
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int h,m;
int x = 0,y = 0;
char s[10] = {0};
memset(s,'0',sizeof(s));
scanf("%d%d%s",&h,&m,s);
if(s[4] == '1')
{
x += s[4]-'0';
if('0' <= s[5] && s[5] <= '9')
{
x *= 10;
x += s[5]-'0';
y = s[7]-'0';
}
else
{
y = s[6]-'0';
}
}
else
{
x = s[4]-'0';
y = s[6]-'0';
}
if(s[3] == '-')
{
x = 10+(14-x);
}
if(x != 8)
{
if(x > 8)
{
h += x-8;
if(y != 0)
{
if(s[3] == '-')
{
m -= 6*y;
if(m < 0)
{
m += 60;
h --;
}
}
else
{
m += 6*y;
if(m > 59)
{
m -= 60;
h ++;
}
}
}
if(h >= 24) h -= 24;
}
else
{
h -= 8-x;
if(y != 0)
{
m += 6*y;
if(m > 59)
{
m -= 60;
h ++;
}
}
if(h < 0) h += 24;
}
printf("%02d:%02d\n",h,m);
}
else
{
if(y != 0)
{
m += 6*y;
if(m > 59)
{
m -= 60;
h ++;
}
}
if(h >= 24) h -= 24;
printf("%02d:%02d\n",h,m);
}
}
return 0;
}
這是我AC了的代碼,開始被卡住了,14時區每分好...............選擇咬舌自盡.。。。。。
菜得不一樣,菜出新高度。