传送门: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. Java类加载器ClassLoader总结

    JAVA类装载方式,有两种: 1.隐式装载, 程序在运行过程中当碰到通过new 等方式生成对象时,隐式调用类装载器加载对应的类到jvm中. 2.显式装载, 通过class.forname()等方法,显 ...

  2. ComfortColor.xcs

    ComfortColor.xcs [comfort color] text=dce2e2text(bold)=dce2e2 magenta=dd3682magenta(bold)=dd3682 whi ...

  3. PL/SQL: numeric or value error: character to number conversion error

    在最简单的plsql块编程中出现这个错误,是因为 DBMS_OUTPUT.PUT_LINE('the x is '+x);这里面不能用“+”,而是要用“||” DECLARE x number; ; ...

  4. Linux-学习笔记(PHP向)<一>

    Linux常用命令 使用PHP服务器端脚本编程语言进行网站开发,需要在lamp环境下进行,Linux作为”四剑客”之一是有必要了解熟悉的,而Linux系统并不像windows操作系统那样,以图形化的界 ...

  5. 2-1 Sass的控制命令

    @if @if 指令是一个 SassScript,它可以根据条件来处理样式块,如果条件为 true 返回一个样式块,反之 false 返回另一个样式块.在 Sass 中除了 @if 之,还可以配合 @ ...

  6. C#开发小技巧

    001.判断一个Form是否已关闭并释放,需要从引用和对象两方面来判断,判断引用是否为null:mainfm==null判断引用的对象是否已释放:mainfm.IsDisposedMainFormma ...

  7. devexpress 中 XtraTabcontrol 改变BackColor 的方法

    装载自CSDN,原文地址  https://blog.csdn.net/zjzytnn/article/details/53699340 今天在实现CAD文件的读和显示操作的时候,需要将CAD文件显示 ...

  8. C# Request获取URL常见用法

    如果测试的url地址是http://www.test.com/testweb/default.aspx, 结果如下: Request.ApplicationPath: /testweb Request ...

  9. iptables:no config file

    防火墙规则默认都是在/etc/sysconfig/iptables这个文件中的 出现这个问题,是因为在/etc/sysconfig/目录下没有找到iptables这个文件 可以使用service ip ...

  10. 哈夫曼树算法及C++实现

    一.相关概念 1.叶子结点的权值(weight)是对叶子结点赋予的一个有意义的数值量. 2.设二叉树有n个带权值的叶子结点,从根节点到各个叶子结点的路径长度与相应叶子结点权值的乘积之和叫做二叉树的带权 ...