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时区每分好...............选择咬舌自尽.。。。。。
菜得不一样,菜出新高度。