【大模拟】 hdu 6308 Time Zone

Time Zone

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

 

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

Source

2018 Multi-University Training Contest 1

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  6318 6317 6316 6315 6314 

先把给出的时间调回UTC+0 然后转化成分钟做,记得补零

因为一些莫名其妙的问题wa了十多发真的百思不得其解

shi、fen一定要初始化,即使之后会赋值

#include<bits/stdc++.h>
using namespace std;
char c[15];
int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int a, b, shi = 0, fen = 0;
        scanf("%d%d", &a, &b);
        scanf("%s", c);
        char s4 = c[3];
        if((c[4] - '0') == 1 && (c[5] - '0') >= 0 && (c[5] - '0') <= 9)
        {
            shi = (c[4] - '0') * 10;
            shi += c[5] - '0';
        }
        else
        {
            shi = c[4] - '0';
        }
        if(c[5] == '.')
        {
            fen = c[6] - '0';
        }
        else if(c[6] == '.')
        {
            fen = c[7] - '0';
        }
        if (fen < 0 || fen >= 10)
            fen = 0;
        a = (a - 8 + 24) % 24;
        int xx = shi * 60 + fen * 6;
        int m = a * 60 + b;
        if (s4 == '+')
            m += xx;
        else
            m -= xx;
        if (m<0)
        {
            int f = (24 + m / 60) % 24;
            if (m % 60 != 0)
                f = (f + 23) % 24;
            if (f < 10)
                printf("0");
            printf("%d:",f);
            if(((60 + m % 60) % 60) < 10)
                printf("0");
            printf("%d\n",(60 + m % 60) % 60);
        }
        else
        {
            if(((24 + m / 60) % 24) < 10)
                printf("0");
            printf("%d:",(24 + m / 60) % 24);
            if(((60 + m % 60) % 60) < 10)
                printf("0");
            printf("%d\n",(60 + m % 60) % 60);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41037114/article/details/81227426