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个数,问有多少种情况满足纳什均衡的点只有一个.纳什均衡点是指这个元素在所在行和所在列都是最大的. 思路:吉老师直播的思路: ...
随机推荐
- spring整合springmvc和mybatis
1.spring 1.1 jar包 1.2 spring基本配置,包扫描注解 <!-- 自动扫描 --> <context:component-scan base-package=& ...
- [android] 练习使用ListView(三)
解决OOM和图片乱序问题 package com.android.test; import java.io.InputStream; import java.net.HttpURLConnection ...
- spring历史和哲学
spring 历史: 2004年 Spring Framework 1.0 final 正式问世. 1.在Spring1.x时代,都是通过xml文件配置bean,随着项目的不断扩大,需要将xml配置分 ...
- 54个提高PHP程序运行效率的方法(转载)
原文地址:http://www.jb51.net/article/69677.htm 1. 如果一个方法可静态化,就对它做静态声明.速率可提升至4倍. 2. echo 比 print 快. 3. 使用 ...
- JavaScript练习笔记整理·1 - 6.23
练习平台Codewars地址:https://www.codewars.com/ 欢迎和大家一起来讨论~╭( ・ㅂ・)و ̑̑ 基础练习(1): 我的解答为: class SmallestIn ...
- FCKeditor 添加行距、字体功能 (转载)
一.首先为FCKeditor添加外部插件在fckeditor/editor/plugins文件夹下建立新文件夹lineHeight,并在其中创建fckplugin.js文件,在其文件中办輸入代码:FC ...
- Linux基础之命令练习Day2-useradd(mod,del),groupadd(mod,del),chmod,chown,
作业一: 1) 新建用户natasha,uid为1000,gid为555,备注信息为“master” 2) 修改natasha用户的家目录为/Natasha 3) 查看用户信息配置文件的最后一行 4) ...
- SSIS 使用OLEDB/ADO NET Source 数据流source控件 连接Oracle失败
在做数据提取的时候发现一个非常奇怪的问题. Oracle客户端是安装正确并且Toad可以正常运行的,但是在新建OLEDB/ADO NET Source 数据流source控件连接Oracle的时候一直 ...
- JAVA程序编写入门
在任意文件夹下创建一个文本,然后重命名,把文本后缀名改为.java.然后用eclipse打开此文件编写程序内容. public class nihao{ public static void main ...
- RC4 加解密
加密解密都是这一个接口 int Rc4EncryptFile(std::string in_file_path, std::string out_file_path, const char *rc4_ ...