Time Zone

Time Zone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5204    Accepted Submission(s): 878

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


題解:將時間全部化爲分鐘。題目關鍵在點在於輸入,以及將double轉化爲int類型

double是不精確的,比如double temp = 1.0,可能它實際上只有0.99999,所以應該加上+0.1之後,再乘10,最後取整就行。

#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
	int n;
	while(~scanf("%d",&n)){
		char str[20];
		while(n--){
			int h,m;
			double s;
			char k;
			scanf("%d %d UTC%c%lf",&h,&m,&k,&s);
			int t = (int) (s *10 + 0.1);
			if(k == '-')
				t = -t;
			int sum = h * 60 +  m +(t *6 - 8*60);
			sum = sum % (24 *60);
			while(sum<0)
				sum += 24 * 60;
			printf("%02d:%02d\n",sum/60,sum %60);				

		}
	}
} 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章