【2018多校第一场】hdu6308-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 (1T106), indicating the number of test cases. For each test case:
The first line contains two integers ab (0a23,0b59) and a string s in the format of "UTC+X'', "UTC-X'', "UTC+X.Y'', or "UTC-X.Y'' (0X,X.Y14,0Y9).
 

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的小时a和分钟b,求 "UTC+X'', "UTC-X'', "UTC+X.Y'', or "UTC-X.Y''的日期是多少。
 
//转化成分钟计算
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    int t, h, m;
    char s[10];
    cin>>t;
    while(t--)
    {
        scanf("%d%d%s", &h, &m, s);
        h = h*60+m;
        int op = s[3]=='+'?1:-1;
        double x;
        sscanf(s+4, "%lf", &x);
        x = (int)(x*10+0.005); //读浮点数会有误差
        int cha = x*6*op-8*60;
        h = (h+cha)%(24*60);
        if(h < 0) h += 24*60;
        printf("%02d:%02d\n", h/60, h%60);
    }
    return 0;
}
posted @ 2018-07-25 19:51  LesRoad  阅读(420)  评论(0编辑  收藏  举报