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.
 
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
 
 
题意:北京标准时间是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[];
scanf("%s",str);
int len=strlen(str);
int flag=;
int th=;
int tm=;
if(str[]=='+'){
for(int i=;i<len;i++){
if(str[i]=='.'){
flag=i;
break;
}
th=th*+str[i]-'';
}
if(flag!=){
tm=str[flag+]-'';
mm+=((tm*)/);
if(mm>=){
mm-=;
th++;
}
}
hh+=(th-);
if(hh>=) hh-=;
if(hh<) hh+=;
if(hh<) cout<<""; //前导零
cout<<hh<<":";
if(mm<) cout<<"";
cout<<mm<<endl;
}else {
int tth=;
int th=;
for(int i=;i<len;i++){
if(str[i]=='.'){
flag=i;
break;
}
tth=tth*+str[i]-'';
}
th-=tth;
if(flag!=){
tm=str[flag+]-'';
mm-=((tm*)/);
if(mm<){
mm+=;
th--;
}
}
hh+=th;
if(hh>=) hh-=;
if(hh<) printf("");
printf("%d:",hh);
if(mm<) printf("");
printf("%d\n",mm);
}
}
return ;
}
/*
01 14 UTC+2.6
19:50
*/

最新文章

  1. 真刀真枪压测:基于TCPCopy的仿真压测方案
  2. [译]Node.js : Building RESTful APIs using Loopback and MySQL
  3. Devexpress TreeList控件绑定显示父子节点对像
  4. 使用Python画ROC曲线以及AUC值
  5. Android Netty框架的使用
  6. ubuntu common
  7. React History
  8. 自定义连接池java.lang.ClassCastException: com.sun.proxy.$Proxy4 cannot be cast to java.sql.Connection
  9. spring cloud+docker 简单说一说
  10. Dynamics 365测试和启用邮箱时候一直显示“安排电子邮件配置测试”怎么办?
  11. Kotlin 的优缺点
  12. ubus socket always in connecting status
  13. Appium(二)---启动App+模拟滑动
  14. 转://云和恩墨的两道Oracle面试题
  15. PAT Basic 1069. 微博转发抽奖(20)
  16. 不同版本Hibernate.获取SessionFactory的方式
  17. 记一次排查局网内的ARP包 “不存在的” MAC 地址及 “不存在的”IP 所发的ARP包
  18. CyclicBarrier的用法
  19. redis error MISCONF Redis is configured to save RDB snapshots
  20. ElasticSearch(一)ElasticSearch的应用场景及为什么要选择ElasticSearch?

热门文章

  1. 计蒜客-----跳跃游戏(C语言)
  2. uva 253 - Cube painting(相同骰子)
  3. R语言学习笔记(三):零碎知识点(1-10)
  4. FIFO队列(First In First Out)和优先队列
  5. 初步学习pg_control文件之七
  6. [转载]Java类打包成JAR文件
  7. 2 web服务器:固定返回值
  8. A problem occurred evaluating project ':'. > ASCII
  9. Hibernate-ORM:08.Hibernate中的投影查询
  10. 从一个线上服务器警告谈谈backlog