CodeForces 387A George and Sleep
2015-08-30 10:16
507 查看
链接:http://codeforces.com/problemset/problem/387/A
memory limit per test:256 megabytes
input:standard input
output:standard output
George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time
t.
Help George! Write a program that will, given time s and
t, determine the time
p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample).
t in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is,
00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59.
Output
Input
Output
Input
Output
"00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all.
大意——给你当前的时间和持续睡眠的时间,问你上床睡觉的时间是何时?所有时间均采用24小时格式。
思路——直接模拟。用当前时间的小时和分钟直接减去持续睡眠时间的小时和分钟即可。最后分别判断一下小时和分钟的符号并做相应处理即可。
复杂度分析——时间复杂度:O(1),空间复杂度:O(1)
附上AC代码:
George and Sleep
time limit per test:1 secondmemory limit per test:256 megabytes
input:standard input
output:standard output
George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time
t.
Help George! Write a program that will, given time s and
t, determine the time
p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample).
Input
The first line contains current time s as a string in the format "hh:mm". The second line contains timet in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is,
00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59.
Output
In the single line print time p — the time George went to bed in the format similar to the format of the time in the input.Sample test(s)
Input05:50 05:44
Output
00:06
Input
00:00 01:00
Output
23:00
Input
00:01 00:00
Output
00:01
Note
In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06","00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all.
大意——给你当前的时间和持续睡眠的时间,问你上床睡觉的时间是何时?所有时间均采用24小时格式。
思路——直接模拟。用当前时间的小时和分钟直接减去持续睡眠时间的小时和分钟即可。最后分别判断一下小时和分钟的符号并做相应处理即可。
复杂度分析——时间复杂度:O(1),空间复杂度:O(1)
附上AC代码:
#include <iostream> #include <cstdio> #include <string> #include <cmath> #include <iomanip> #include <ctime> #include <climits> #include <cstdlib> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <set> #include <map> //#pragma comment(linker, "/STACK:102400000, 102400000") using namespace std; typedef long long ll; const double pi = acos(-1.0); const double e = exp(1.0); const double eps = 1e-8; short chour, cmin; short lhour, lmin; int main() { ios::sync_with_stdio(false); while (~scanf("%hd:%hd", &chour, &cmin)) { scanf("%hd:%hd", &lhour, &lmin); int hour = chour-lhour; int min = cmin-lmin; if (min < 0) { min += 60; hour -= 1; } if (hour < 0) hour += 24; printf("%02d:%02d\n", hour, min); } return 0; }
相关文章推荐
- zsh配置
- 1105 -- 绝对值
- 你不能不了解硬件
- 在青岛穷游打的cf codeforces Round #318 (Div. 2) A.Bear and Elections
- LeetCode(268) Missing Number
- HTTP请求过程详解
- 1104 -- 打折
- 51单片机的data,xdata,code的区别详解
- 图理解单链表的反转
- linux命令汇总(wc、cut、sort、uniq)
- Win8 分区教程
- 1103 -- 偶数
- 1102 -- 两点距离
- Java系列笔记 - Java 内存区域和GC机制
- Java基础知识强化07:打印出空心菱形
- Java中的main()方法详解
- mysql 表查询
- 1101 -- 正弦和余弦
- JVM命令行
- codeforces gym 100345I Segment Transformations [想法题]