2018 杭电多校Contest 1 : 1011 Time Zone 时区转换

Time Zone

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


 

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

 

[思路]

UTC-8 是 西八区, 西八区和东八区 差16 个小时,  西八区在东八区前面,

1 = 1h ; 0.1 = 6 分钟;

当UTC + 时,以 UTC+8 东八区为标准,   在此基础上 +9  是 增加,  +7  是减少,

当UTC -  时,以 UTC-8  西八区为标准,,  在此基础上 -9 是 增加, -7 是减少,  然后 换算成 东八区 ;

从东八区(UTC+8)  换到 西八区(UTC-8)   -16;  

[代码]

#include 
#include 
/*
*
* Author : siz
*
*/
using namespace std;

typedef long long ll;

const int modH = 24;
const int modM = 60;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {

        int a, b;
        char str[50];
        scanf("%d %d %s",&a,&b,str);
        int len = strlen(str);
        int flag = 0 ;
        int d=0,p = 0;
        for(int i = 4 ; i < len ; i++)
        {
            if( str[i]=='.')
            {
                flag = 1;
                continue;
            }

            if( !flag)
                d = d*10 + str[i]-'0';
            else
                p = p*10 + str[i]-'0';
        }
        p = p*6;
        if(str[3]=='+')
        {
            if( b+p >= modM)
                a++;
            a = (a + d-8+ modH) %modH;
            b = (b + p+modM)%modM;
        }
        else
        {
            if( b - p  < 0)
                a--;
             a = ( a-16 -(d-8) + modH) %modH;
             b = ( b - p + modM)%modM;
        }
        printf("%02d:%02d\nS",a,b)W;

    }
}

 

你可能感兴趣的:(ACM进阶之路)