HDU 6308 Time Zone(模拟)

【题目链接】
http://acm.hdu.edu.cn/showproblem.php?pid=6308

题目意思

给你+8的时区的时间,问你uct的时间?

解题思路

模拟就可以了,如果转化成分钟相减再化成时间要注意负数。

代码部分


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <string>
#include <map>
#include <math.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3
const int mod = 1e9+7;
const int N = 1e3+7;
int n,m;
char str[20];
int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        double uct;
        bool fa;
        int time;
        scanf("%d %d %s",&n,&m,str);
        time = 60*n+m;
        sscanf(str+4,"%lf",&uct);
        if (str[3] == '-')
        {
            fa = false;
        }
        else fa = true;
        if (!fa)
        {
            uct = 4+(12-uct);
        }
        else uct = uct-8;
        if (uct >= 0)
            time += (int)(uct*60+0.1);
        else time += (int)(uct*60-0.1)+24*60;
        printf("%02d:%02d\n",(time/60)%24,time%60);
    }
    return 0;
}
/*
100
00 00 UTC+8
00 00 UTC+9
00 00 UTC+10.2
00 56 UTC+11.2
00 00 UTC+0
00 06 UTC+0.1
00 00 UTC+3
00 06 UTC+3.9
00 00 UTC-11
00 00 UTC-11.1
*/

猜你喜欢

转载自blog.csdn.net/pashuihou/article/details/81178782
今日推荐