A. Karen and Morning
来源:互联网 发布:java和asp.net的区别 编辑:程序博客网 时间:2024/05/29 03:55
Karen is getting ready for a new school day!
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?
Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
The first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
05:39
11
13:31
0
23:59
1
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
解题说明:此题是一道回文字符判断题,可以采用遍历的方法,直到找到最近的回文数字。
#include<cstdio>#include<algorithm>#include<cstring>#include<cstdlib>#include<iostream>using namespace std;int main(void){int hour,min,h1,h2,m1,m2,i;scanf("%d:%d",&hour,&min);for(i=0; ;i++) {h2=hour%10;h1=hour/10;m2=min%10;m1=min/10;if(h1==m2 && h2==m1) {printf("%d\n",i);return 0;}if(hour==23 && min==59) {printf("%d\n",i+1);return 0;}min++;if(min>59) {min=0;hour++;}}return 0;}
- A. Karen and Morning
- cf419 A Karen and Morning
- codeforces A Karen and Morning 傻瓜模拟
- CodeForce Round #479 A. Karen and Morning
- Codeforces 816A-Karen and Morning
- codeforces 816A Karen and Morning
- CodeForces 816A Karen and Morning
- CF816A-Karen and Morning
- Karen and Morning
- Codeforces816A Karen and Morning
- Karen and Morning
- Karen and Morning
- Codeforces Round #419 (Div. 2) A. Karen and Morning
- Codeforces Round #419 A. Karen and Game
- Codeforces 815A-Karen and Game
- CF816B-Karen and Coffee
- Karen and Coffee codeforces
- CF816B-Karen and Coffee
- 基于Win32控制台的万年历的实现(上)
- 全面解析Linux 内核 3.10.x
- select服务器---I/O多路连接之select
- Javascript再改造(1)——数据类型和变量
- Saber电路仿真软件
- A. Karen and Morning
- win10开机后黑屏一段时间(amd显卡)
- [编程题] 下厨房
- 线程清理函数
- 全面解析Linux 内核 3.10.x
- Jetty8——实现Servlet 3 注解
- 在jsp中如何引入css的三种方法
- Kotlin官方参考整理——05.其他
- (六)MySQL 基础(练习二)