传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6308
Time Zone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5017 Accepted Submission(s): 1433
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.
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).
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
题意概括:
给出北京时间(北京时区为UTC+8),和需要转换成的目的时间的时区;
求出目的时区的时间;
解题思路:
模拟:
小时和分钟分开处理计算
+时区和 -时区要注意两个加减时间不同的问题,+时区比-时区时间早;
字符转换为整型 atoi(str)
字符转换为双精度浮点型 atof(str)
(当然也可以选择自己手敲一个转换表达式,位数不多)
AC code:
1 #include <queue> 2 #include <cstdio> 3 #include <vector> 4 #include <cstring> 5 #include <iostream> 6 #include <algorithm> 7 #define INF 0x3f3f3f3f 8 #define LL long long 9 using namespace std; 10 const int MOD1 = 24; 11 const int MOD2 = 60; 12 const int MAXN = 20; 13 char str[MAXN]; 14 15 int main() 16 { 17 int a, b; 18 int T_case; 19 scanf("%d", &T_case); 20 while(T_case--){ 21 scanf("%d %d %s", &a, &b, &str); 22 //printf("%d %d %s ", a, b, str); 23 bool flag = false; 24 char aa[MAXN], top1=0, bb[MAXN], top2=2; 25 bb[0] = '0'; 26 bb[1] = '.'; 27 for(int i = 4; i < strlen(str); i++){ 28 29 if(str[i] == '.'){ flag = true; continue;} 30 if(!flag){ 31 aa[top1++] = str[i]; ///zhengshuu 32 } 33 else{ 34 bb[top2++] = str[i]; ///xiaoshu 35 } 36 } 37 aa[top1] = '