• hdu 6308 Time Zone (模拟+字符串处理)


    Time Zone

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


    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的时间,求给定时区的时间。
     
    模拟题。
    是水题没错的,但是不仔细做还是会wa得很惨QAQ...
    1、这里的时区并不是标准的时区定义,所以直接根据差值加减就好啦。
    2、转化成分钟加加减减或许是最好的方法。
    3、X可能是两位数。
    我是先把给的时间转移到UTC+0(UTC-0),这样处理起来感觉更方便。
     
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<cmath>
    
    using namespace std;
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int a,b;
            char s[10];
            scanf("%d%d%s",&a,&b,s);
            int minute=a*60+b-8*60;
    
            int add=0,pos;
            for(pos=4;s[pos]!='';pos++)
            {
                if(s[pos]=='.')break;
                add=add*10+s[pos]-'0';
            }
            if(s[pos]=='.')add=add*60+(s[pos+1]-'0')*6;
            else add=add*60;
    
            if(s[3]=='+')
                minute+=add;
            else
                minute-=add;
            if(minute>=24*60)
                minute=minute-24*60;
            if(minute<0)
                minute=minute+24*60;
    
            printf("%02d:%02d
    ",minute/60,minute%60);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    【Algorithm】基数排序
    【Algorithm】堆排序
    【Algorithm】快速排序
    【Algorithm】自顶向下的归并排序
    【Algorithm】自底向上的归并排序
    【Algorithm】插入排序
    【Algorithm】选择排序
    java的几个format
    java restful接口
    java解析EXCEL
  • 原文地址:https://www.cnblogs.com/acboyty/p/9683973.html
Copyright © 2020-2023  润新知