传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6308

Time Zone

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

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),和需要转换成的目的时间的时区;

求出目的时区的时间;

解题思路:

模拟:

小时和分钟分开处理计算

+时区和 -时区要注意两个加减时间不同的问题,+时区比-时区时间早;

字符转换为整型 atoi(str)

字符转换为双精度浮点型 atof(str)

(当然也可以选择自己手敲一个转换表达式,位数不多)

AC code:

 #include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int MOD1 = ;
const int MOD2 = ;
const int MAXN = ;
char str[MAXN]; int main()
{
int a, b;
int T_case;
scanf("%d", &T_case);
while(T_case--){
scanf("%d %d %s", &a, &b, &str);
//printf("%d %d %s\n", a, b, str);
bool flag = false;
char aa[MAXN], top1=, bb[MAXN], top2=;
bb[] = '';
bb[] = '.';
for(int i = ; i < strlen(str); i++){ if(str[i] == '.'){ flag = true; continue;}
if(!flag){
aa[top1++] = str[i]; ///zhengshuu
}
else{
bb[top2++] = str[i]; ///xiaoshu
}
}
aa[top1] = '\0';bb[top2]='\0';
double num_it = ;
int num_b;
int num_a = atoi(aa);
if(flag){
num_it = atof(bb);
num_b = (int)(num_it*);
}
//printf("num_a:%d num_b:%d\n", num_a, num_b);
///*
if(str[] == '+'){
if(num_a >= ) num_a-=;
else if(num_a < ) num_a = -+num_a;
if(flag){
num_a = num_a+(b+num_b)/;
b = (b+num_b)%MOD2;
}
a=((a+num_a)%MOD1 + MOD1)%MOD1;
} if(str[] == '-'){ if(flag){
//num_a = num_a-(b+num_b)/60;
b = (b-num_b)%MOD2;
if(b < ) num_a++;
b = (b+MOD2)%MOD2;
}
a = ((a-num_a+)%MOD1+MOD1)%MOD1;
} if(a<) printf("0%d:", a);
else printf("%d:", a); if(b<) printf("0%d\n", b);
else printf("%d\n", b);
//*/
}
return ;
}

Time Zone 【模拟时区转换】(HDU暑假2018多校第一场)的更多相关文章

  1. 【2018多校第一场】hdu6308-Time Zone(日期)

    Problem Description Chiaki often participates in international competitive programming contests. The ...

  2. HDU6300(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6300 排个序就好了 #include<iostream> #include& ...

  3. HDU6301(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6301 队友AC的,没怎么看 #include<iostream> #incl ...

  4. HDU6308(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6308 将时间化简为分钟计算,同时不要用浮点数计算,精度会出现问题: 如果采用精度,最好加 ...

  5. HDU6299(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6299 两个字符串的排序可以分成四种情况: (1)str1左少右多 vs str2 左多右 ...

  6. HDU6298(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6298 打表找规律: #include<bits/stdc++.h> usin ...

  7. hdu 5289 Assignment(2015多校第一场第2题)RMQ+二分(或者multiset模拟过程)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5289 题意:给你n个数和k,求有多少的区间使得区间内部任意两个数的差值小于k,输出符合要求的区间个数 ...

  8. 杭电2018暑假多校第一场 D Distinct Values hdu6301 贪心

    Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. 2018多校第九场1004(HDU 6415) DP

    本以为是个找规律的题一直没找出来... 题目:给你一个n*m的矩阵和1-n*m个数,问有多少种情况满足纳什均衡的点只有一个.纳什均衡点是指这个元素在所在行和所在列都是最大的. 思路:吉老师直播的思路: ...

随机推荐

  1. 清除SQL Server内存

    数据库进行查询时,会缓存结果集,当查询结果过大时会出现内存爆满的情况,如果手动清除SQL所占用的内存呢,在网上搜索一下,把结果贴下面: --强制释放内存 Create procedure [dbo]. ...

  2. springmvc4集成swagger2

    首先在原有的springmvc工程的pom文件中增加swagger <dependency> <groupId>io.springfox</groupId> < ...

  3. Application全局应用程序类

    当一个WPF应用程序启动时,先会实例化一个全局的唯一的Application.如果开发人员熟悉Windows Form编程,会知道在SystemWindowsForm命名空间中有一个Applicati ...

  4. 互联网轻量级框架SSM-查缺补漏第三天

    简言:平安夜,继续慵懒的学习.我真的是不喜欢学习··· 第三章认识MyBatis核心组件 3.1 持久层的概念和MyBatis的特点 持久层:可以将业务数据存储带磁盘,具有长期存储的能力.一般执行持久 ...

  5. springboot遇到的那些坑

    一.在springboot整合jsp时,程序中的所有配置都是正确的,但是在启动springboot后,访问无法找到jsp页面,报错404, 解决办法 二.在springboot整合jpa实现crud时 ...

  6. autocomplete 属性 清除input框输入存留历史值,防止下拉历史值显示

    autocomplete 属性规定输入字段是否应该启用自动完成功能. 自动完成允许浏览器预测对字段的输入.当用户在字段开始键入时,浏览器基于之前键入过的值,应该显示出在字段中填写的选项. 注释:aut ...

  7. Linux基础之-正则表达式(grep,sed,awk)

    一. 正则表达式 正则表达式,又称规则表达式.(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表达式是对字符串操作的一种逻辑公 ...

  8. 基于Docker搭建GitLab服务器

    运行环境:CentOS 7.4 一.安装Docker Docker安装可以参照runoob教程(http://www.runoob.com/docker/centos-docker-install.h ...

  9. hdu 4513 吉哥系列故事——完美队形II (manachar算法)

    吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) P ...

  10. MSSQLServer——全国省份城市SQL语句

    use hr create table dbo.province ( proID int primary key, proName ), keys ) ) ,'北京市','B'); ,'天津市','T ...