Codeforces816A Karen and Morning
来源:互联网 发布:创业软件 俞青 编辑:程序博客网 时间:2024/06/18 17:59
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 <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <cmath>using namespace std;#define LL long longconst int inf=0x7fffffff;bool check(int h,int m){ if(h/10+(h%10)*10==m) return 1; return 0;}int main(){ int h,m; while(~scanf("%d:%d",&h,&m)) { int ans=0; while(!check(h,m)) { ans++; m++; if(m==60) h+=1,m=0; if(h==24) h=0; } printf("%d\n",ans); } return 0;}
或者干脆蠢一点根据时间分类讨论
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <cmath>using namespace std;#define LL long longconst int inf=0x7fffffff;int main(){ int h,m; while(~scanf("%d:%d",&h,&m)) { int t=h*60+m; int ans; if(h<5||(h==5&&m<=50)) { int fm=h*10; if(m<=fm) { ans=fm-m; } else { fm=(h+1)*10; ans=(h+1)*60+fm-t; } } else if(h<=9) { ans=10*60+1-t; } else if(h<15||(h==15&&m<=51)) { int fm=(h%10)*10+(h/10); if(m<=fm) { ans=fm-m; } else { fm=((h+1)%10)*10+((h+1)/10); ans=(h+1)*60+fm-t; } } else if(h<=19) { ans=20*60+2-t; } else if(h<23||(h==23&&m<=32)) { int fm=(h%10)*10+(h/10); if(m<=fm) { ans=fm-m; } else { fm=((h+1)%10)*10+((h+1)/10); ans=(h+1)*60+fm-t; } } else { ans=24*60-t; } printf("%d\n",ans); } return 0;}
- Codeforces816A Karen and Morning
- CF816A-Karen and Morning
- 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
- box-sizing属性解析
- ubuntu ssd-caffe 配置问题之syntax error near unexpected token '('
- Linux--线程死锁
- 自动提取文本关键词demo
- vue的学习记录-例题
- Codeforces816A Karen and Morning
- poi3.9导入导出 讲解实例
- JDE表对应DB视图
- Python3 字符串操作
- java反射
- 网页中嵌套图片的输出格式说明
- 面试 42-1:翻转单词顺序
- asp 指定读取某篇文章
- c语言中.c与.h文件详解