HDU 多校对抗赛 J Time Zone
2024-08-27 14:23:13
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
11 11 UTC+8
11 12 UTC+9
11 23 UTC+0
Sample Output
11:11
12:12
03:23
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
*/
最新文章
- 真刀真枪压测:基于TCPCopy的仿真压测方案
- [译]Node.js : Building RESTful APIs using Loopback and MySQL
- Devexpress TreeList控件绑定显示父子节点对像
- 使用Python画ROC曲线以及AUC值
- Android Netty框架的使用
- ubuntu common
- React History
- 自定义连接池java.lang.ClassCastException: com.sun.proxy.$Proxy4 cannot be cast to java.sql.Connection
- spring cloud+docker 简单说一说
- Dynamics 365测试和启用邮箱时候一直显示“安排电子邮件配置测试”怎么办?
- Kotlin 的优缺点
- ubus socket always in connecting status
- Appium(二)---启动App+模拟滑动
- 转://云和恩墨的两道Oracle面试题
- PAT Basic 1069. 微博转发抽奖(20)
- 不同版本Hibernate.获取SessionFactory的方式
- 记一次排查局网内的ARP包 “不存在的” MAC 地址及 “不存在的”IP 所发的ARP包
- CyclicBarrier的用法
- redis error MISCONF Redis is configured to save RDB snapshots
- ElasticSearch(一)ElasticSearch的应用场景及为什么要选择ElasticSearch?
热门文章
- 计蒜客-----跳跃游戏(C语言)
- uva 253 - Cube painting(相同骰子)
- R语言学习笔记(三):零碎知识点(1-10)
- FIFO队列(First In First Out)和优先队列
- 初步学习pg_control文件之七
- [转载]Java类打包成JAR文件
- 2 web服务器:固定返回值
- A problem occurred evaluating project ':'. > ASCII
- Hibernate-ORM:08.Hibernate中的投影查询
- 从一个线上服务器警告谈谈backlog