传送门: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. .net core 部署到IIS上 HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure

    安装AspNetCoreModule托管模块后执行 1.net stop was /y 2.net start w3svc

  2. 点击checkbox全选,其它被选中,再点击取消

    <input type="checkbox" value="" id="checkall" name="" siz ...

  3. java 线程池(1)

    问题 : 线程池中的 coreSize 和 maxSize 的作用分别是什么? 未执行的线程池存在在哪种数据类型,为什么使用这种类型的数据结构 ThreadPoolExecutor概述 ThreadP ...

  4. Linux服务器安装tomcat、JDK、SVN等常用开发软件总结

    本来本文发布到首页的,该网站运营人员移除了,说我这篇博文太简单了,如果感觉我这篇博文有用的,大家给个推荐,打一下运营人员的脸 目录 一.Ubuntu 16.04下安装JDK(spring 3.2不支持 ...

  5. vue-构建项目相关事项

    安装 :vue-cli npm install -g vue-cli 使用webpack 打包 vue 項目的創建: vue init webpack 項目名子 生產基本的項目結構后 進入到項目目錄 ...

  6. SpringCloud+Git+Maven+Docker+Jenkins自动化构建

    1.JDK安装-OpenJDK安装 yum list java-1.8* yum install -y java-1.8.0-openjdk-devel.x86_64 PS: JDK安装有两种方法:一 ...

  7. C++中 set(集合容器)的用法

    set集合容器: 实现了红黑树(Red-Black Tree)的平衡二叉检索树的数据结构,在插入元素时, 它会自动调整二叉树的排列,把该元素放到适当的位置,以确保每个子树根节点的键值大于左子树所有节点 ...

  8. 12_Redis缓存穿透

    [何为缓存穿透] 缓存穿透是查询一个一定不存在的数据,这样的请求都要到存储层MySql去查询,失去了缓存的意义,在流量大时,可能MySql就挂掉了,要是有人利用不存在的key频繁攻击我们的应用,这就是 ...

  9. 【创客+】偷心锁屏创始人Jerry创业心得分享

    偷心锁屏创始人Jerry创业心得分享 作者:Jerry权泉,偷心锁屏创始人 我创业的起因非常偶然.08年在东京早稻田大学读博士期间,每周六都去社区活动中心跟日本人志愿者日语对话练习日语.有一次练习结束 ...

  10. Android Studio修改app图标

    1.将下载好的图片放到app\src\main\res\drawable目录下 2.在AndroidManifest.xml下加入一句 android:icon="@drawable/??? ...