CodeForce Round #479 A. Karen and Morning
来源:互联网 发布:淘宝最帅男模特顾义伟 编辑:程序博客网 时间:2024/06/16 05:53
传送门:点击打开链接
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, because05: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<iostream>#include<algorithm>using namespace std;int main(){char a[15];int i;while(cin>>a){int h=(a[0]-'0')*10+(a[1]-'0');int m=(a[1]-'0')*10+(a[0]-'0');int mm=(a[3]-'0')*10+(a[4]-'0');if(mm==m){cout<<"0"<<endl;continue;}for(i=0;;i++){if(mm==m)break;mm++;if(mm==60){h++;h=h%24;mm=0;m=(h%10)*10+h/10;}}cout<<i<<endl;}return 0;}
- CodeForce Round #479 A. Karen and Morning
- A. Karen and Morning
- CodeForce Round #479 B. Karen and Coffee
- Codeforces Round #419 (Div. 2) A. Karen and Morning
- cf419 A Karen and Morning
- codeforces 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 A. Karen and Game
- 【Codeforces Round #419 (Div. 1)】Codeforces 815A Karen and Game
- Round#419 C Karen and Game
- Codeforces 815A-Karen and Game
- Hadoop基础教程-第7章 MapReduce进阶(7.3 MapReduce API)(草稿)
- mybatis入门案例1
- response.redirect和server.Transfer的差别详解
- Uva.10340 All in All
- rrr
- CodeForce Round #479 A. Karen and Morning
- GreenDao3.0在Android Studio中的简单使用
- 【websocket】——用户登录实现广播
- C++中的虚函数与虚函数表、虚函数表指针
- 【机器学习算法模型】分类算法——朴素贝叶斯
- 天才黑客打脸乔布斯玩转索尼叫板特斯拉!
- Activity的LaunchMode和退出应用程序
- Keil C51 实现 printf 函数
- 【白兔兔】用TiKZ画2017高考全国1卷理科数学流程图