Time Zone

 

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

题意:北京时区为UTC+8,随意给定UTC+X,UTC+X.Y,UTC-X,UTC-X.Y与北京时区相比的时区的值,然后以北京时间为标准时间,通过时区的差值比较,问该时区的时间为多少。

这个题注意时区的换算就可以了,还有就是要避免时间为负和时间超过24时

#include
#include
int main()
{
    int f,a,b,flag,x,y,i; 
    char s[20];
	scanf("%d",&f);
    while(f--){
        flag=1;
		x=0;
		y=0;
       
        scanf("%d %d %s",&a, &b, s);

        int l=strlen(s);
        for(i=0;i='0'&&s[i]<='9')
                x=x*10+(int)(s[i]-'0');

            else if(s[i]=='.'){
                y=(int)(s[i+1]-'0');
                break;
            }
        }
        
        if(flag==1){  //x,y表示减完差值后的值 
            if(y==0) 
				a=(a+(x-8)+24)%24;//分的变化为0,直接进行时的加法变化即可 
            else{
                b+=y*6;  //因为北京时间8=8.0;b+=y*6就相当于b+=(y-0)*6;  
                a=(a+(x-8)+b/60+24)%24;//如果x>=8,a=a+(x比8多的差值)+(可能存在的进位); 
                b%=60;                 //如果0

 

你可能感兴趣的:(思维,基础题,7--24--)