Time Zone

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 Outpu

11:11 12:12 03:23

题意;

输入时分为+8时的,根据时区,判断该时区的时间

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int  t,i,j,x,y,fri,sec;
    double ss;
    char s[20];
    bool flag,ok1,ok2;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%s",&x,&y,s);
        //cin>>s;
        flag=0;
        ok1=0;
        ok2=0;
        if(s[3]=='-')
            flag=1;
        int m;
        m=0;
        //printf("%c\n",s[4]);
        for(j=4;j<strlen(s);j++)
        {
            if(s[j]=='.')
               break;
            m=m*10+(s[j]-'0');
            //printf("dddd %d\n",m);
        }
        j++;
        ss=m;
        double aa;
        aa=0.1;
        for(;j<strlen(s);j++,aa*=0.1)
        {
            ss+=aa*(s[j]-'0');
        }
        int now;
        double pre;
        now=ss;//
        pre=ss-now;
        pre=pre*60;
        int tt;
        tt=(int)(pre+0.9);//
        //printf("%d %d\n",now,tt);
        //printf("%f\n",pre);
        if(flag)
        {
            //printf("ok\n");
            now=8+now;
            ok2=0;
            if(y<tt)
            {
                ok2=1;
                sec=60-tt+y;
            }
            else
                sec=(60+y-tt)%60;
            if(ok2)
            {
                fri=(24+x-now-1)%24;
            }
            else
                fri=(24+x-now)%24;
        }
        else
        {
            if(now<8)
            {

                if(tt>0)
                now=8-now-1;
                else
                now=8-now;
                ok2=0;
                if(y<60-tt&&tt)
                {
                    ok2=1;
                    sec=(60-(60-tt)+y)%60;
                }
                else
                    sec=(60+y-(60-tt))%60;
                //printf("%d\n",ok2);
                if(ok2)
                {
                    fri=(24+x-now-1)%24;
                }
                else
                    fri=(24+x-now)%24;
            }
            else
            {
                ok2=0;
                sec=(y+tt)%60;
                ok2=(y+tt)/60;
                fri=(24+x+now-8+ok2)%24;
            }
        }
       // cout<<"sss"<<endl;
        if(fri<10)
            printf("0");
        printf("%d:",fri);
        if(sec<10)
            printf("0");
        printf("%d\n",sec);
    }
}
/*
110
0 0 fds+8
0 0 dfs+7
*/

猜你喜欢

转载自blog.csdn.net/lml11111/article/details/81174714