Karen and Morning
来源:互联网 发布:杨千嬅歌曲评价知乎 编辑:程序博客网 时间:2024/06/06 11:00
Karen is getting ready for a new school day!
It is currently hh:mm, given in a 24-hour format. As you know, Karen lovespalindromes, 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 is11. 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 is1 minute. She can wake up at 00:00, when the time is a palindrome.
其实回文的情况就那么多,枚举出来一个二分查找就可以了;
#include<bits/stdc++.h>using namespace std;int save[30];int main(){ save[0]=0; save[1]=1*60+10; save[2]=2*60+20; save[3]=3*60+30; save[4]=4*60+40; save[5]=5*60+50; save[6]=10*60+1; save[7]=11*60+11; save[8]=12*60+21; save[9]=13*60+31; save[10]=14*60+41; save[11]=15*60+51; save[12]=20*60+2; save[13]=21*60+12; save[14]=22*60+22; save[15]=23*60+32; save[16]=24*60; int a,b; while(scanf("%d:%d",&a,&b)!=EOF) { int n=lower_bound(save,save+17,a*60+b)-save; printf("%d\n",save[n]-a*60-b); }}
- CF816A-Karen and Morning
- Karen and Morning
- Codeforces816A Karen and Morning
- A. Karen and Morning
- Karen and Morning
- 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
- Codeforces Round #419 (Div. 2) A. Karen and Morning
- CF816B-Karen and Coffee
- Karen and Coffee codeforces
- CF816B-Karen and Coffee
- C. Karen and Game
- Karen and Game Codeforces
- Docker Toolbox 使用小技巧-复制粘贴-批量处理-循环语句-dm别名
- linux 扩展swap分区大小
- Android框架之Camera(3)透过Camera服务看Binder进程间通信
- PHP四种基础排序算法--冒泡,直接插入,快速和选择排序
- (2) JDBC建立连接实例
- Karen and Morning
- centos 下ueditor上传图片502
- servlet基础及过滤器简介
- 我的第一个shell脚本
- Asp.net控件集了解
- 音视频基础
- haskell learning beginner
- Java集合—Set集合
- STM32官网下载库文件