HDU 多校对抗赛 J Time Zone
Posted buerdepepeqi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 多校对抗赛 J Time Zone相关的知识,希望对你有一定的参考价值。
Time Zone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 495 Accepted Submission(s): 162
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.
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).
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
题意:北京标准时间是UTC+8
现在给出标准的北京时间和别的地方的时区
要求别的地方的当前时间
模拟题:
注意细节:1 会有浮点误差,所以把小数位拿出来单独计算
2注意当h小于0的时候,要转换成前一天的时间
3是UTC-xy时,可以当成是当前时间+16-xy的时间
代码如下
#include <cstdio> #include <algorithm> #include <iostream> #include <cstring> using namespace std; int main(){ int T; scanf("%d",&T); while(T--){ int hh,mm; scanf("%d%d",&hh,&mm); char str[100]; scanf("%s",str); int len=strlen(str); int flag=0; int th=0; int tm=0; if(str[3]==‘+‘){ for(int i=4;i<len;i++){ if(str[i]==‘.‘){ flag=i; break; } th=th*10+str[i]-‘0‘; } if(flag!=0){ tm=str[flag+1]-‘0‘; mm+=((tm*60)/10); if(mm>=60){ mm-=60; th++; } } hh+=(th-8); if(hh>=24) hh-=24; if(hh<0) hh+=24; if(hh<10) cout<<"0"; //前导零 cout<<hh<<":"; if(mm<10) cout<<"0"; cout<<mm<<endl; }else { int tth=0; int th=16; for(int i=4;i<len;i++){ if(str[i]==‘.‘){ flag=i; break; } tth=tth*10+str[i]-‘0‘; } th-=tth; if(flag!=0){ tm=str[flag+1]-‘0‘; mm-=((tm*60)/10); if(mm<0){ mm+=60; th--; } } hh+=th; if(hh>=24) hh-=24; if(hh<10) printf("0"); printf("%d:",hh); if(mm<10) printf("0"); printf("%d ",mm); } } return 0; } /* 01 14 UTC+2.6 19:50 */
以上是关于HDU 多校对抗赛 J Time Zone的主要内容,如果未能解决你的问题,请参考以下文章
2017多校第4场 HDU 6078 Wavel Sequence DP