Time Zone 【模拟时区转换】(HDU暑假2018多校第一场)
传送门: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
Given a time in Beijing time (UTC +8), Chiaki would like to know the time in another time zone s.
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).
题意概括:
给出北京时间(北京时区为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多校第一场)的更多相关文章
- 【2018多校第一场】hdu6308-Time Zone(日期)
Problem Description Chiaki often participates in international competitive programming contests. The ...
- HDU6300(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6300 排个序就好了 #include<iostream> #include& ...
- HDU6301(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6301 队友AC的,没怎么看 #include<iostream> #incl ...
- HDU6308(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6308 将时间化简为分钟计算,同时不要用浮点数计算,精度会出现问题: 如果采用精度,最好加 ...
- HDU6299(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6299 两个字符串的排序可以分成四种情况: (1)str1左少右多 vs str2 左多右 ...
- HDU6298(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6298 打表找规律: #include<bits/stdc++.h> usin ...
- hdu 5289 Assignment(2015多校第一场第2题)RMQ+二分(或者multiset模拟过程)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5289 题意:给你n个数和k,求有多少的区间使得区间内部任意两个数的差值小于k,输出符合要求的区间个数 ...
- 杭电2018暑假多校第一场 D Distinct Values hdu6301 贪心
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 2018多校第九场1004(HDU 6415) DP
本以为是个找规律的题一直没找出来... 题目:给你一个n*m的矩阵和1-n*m个数,问有多少种情况满足纳什均衡的点只有一个.纳什均衡点是指这个元素在所在行和所在列都是最大的. 思路:吉老师直播的思路: ...
随机推荐
- java编写简单的语法分析预测程序
编译原理课程中,编了一个简单的语法分析预测程序,这个程序时根据固定的文法得到预测分析表,然后编写程序来判断表达式是否会正确推到出来. 前提是程序没有左递归符合LL(1)文法: 文法如下: E→TE' ...
- linux设置静态获取ip
vsphere client 创建虚拟机后,默认是动态获取ip ,如果想要改为静态ip: 修改网卡eth0 (不一定每个人都是eth0,比如有的是ens160) vim /etc/sysconfig/ ...
- 为My97DatePicker日期插件设置默认日期
datepicker.zip 为My97DatePicker日期插件设置默认日期,开始日期为系统日期的前一个月,结束日期为系统日期: 开始日期不能大于结束日期,且都不能大于今天: 开始日期-maxDa ...
- thinkphp下判断状态值语法
在thinkphp框架下我们经常会用到状态值的判断:但是这样写会引起语法错误. <div> <if condition="{$res.status} eq '0'" ...
- 使用mpvue搭建一个初始小程序
1. 初始化一个 mpvue 项目 现代前端开发框架和环境都是需要 Node.js 的,如果没有的话,请先下载 nodejs 并安装. 然后打开命令行工具: # 1. 先检查下 Node.js 是否安 ...
- JavaEE之会话技术Cookie&Session
会话技术简介 存储客户端的状态 由一个问题引出今天的内容,例如网站的购物系统,用户将购买的商品信息存储到哪 里?因为Http协议是无状态的,也就是说每个客户访问服务器端资源时,服务器并 ...
- centos7编译安装git最新版
假如系统已经安装了git,先删除. 如果是通过yum安装的,直接在终端使用以下指令删除: yum remove git 如果是通过源码编译安装的,参考以下文章: Linux ./configure & ...
- 获取页面z-index最大值
getMaxZIndex = function () { var maxZ = Math.max.apply(null, $.map($('body *'), function(e,n) { if ( ...
- CentOS7 下安装 SublimeText3
原文地址:http://www.sundabao.com/centos-%E5%AE%89%E8%A3%85sublime-text-3/ Centos 安装Sublime text 3 Centos ...
- hiho一下 第一周 最长回文子串
时间限制:1000ms 单点时限:1000ms 内存限制:64MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进. 这 ...