codeforces 816A
来源:互联网 发布:迅龙数据恢复下载安装 编辑:程序博客网 时间:2024/05/18 01:30
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<bits/stdc++.h>using namespace std;const int maxn=10;int a[maxn];int main(){ string s; int num1=0,num2=0; while(cin>>s) { memset(a,0,sizeof(a)); int len=s.length(); int cnt=0; for(int i=0;i<len;i++) { if(s[i]==':') continue; a[cnt++]=s[i]-'0'; } int num=a[0]*10+a[1]; num1=a[0]+a[1]*10; num2=a[2]*10+a[3]; int sum=0; if(num==23&&num2<=32) { sum=32-num2; cout<<sum<<endl; continue; } else if(num==23&&num2>32) { sum=60-num2; cout<<sum<<endl; continue; } else { while(1) { if(num2==60) { num2=0; if(num1==90) { num1=1; } else if(num1==91) { num1=2; } else { num1+=10; } } if(num1==num2) break; sum++; num2++; } cout<<sum<<endl; } } return 0;}
- codeforces 816A
- CodeForces-a
- Codeforces 903A A
- Codeforces 816A-Karen and Morning
- codeforces 816A Karen and Morning
- CodeForces 816A Karen and Morning
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- codeforces#99 a
- codeforces 105 div2 A
- codeforces #121 A
- java注册页面
- Ubuntu编译安装llvm-clang
- MySQL数据库中的存储引擎
- 搭建frp实现树莓派内网穿透
- centos 6.x下安装nodejs
- codeforces 816A
- cf#419 Karen and Coffee 前缀和
- linux与window文件目录共享——samba配置及在windows映射
- 微型技术博客之静态类
- 最小费用最大流模版
- 用python爬取百科糗事的小项目
- Lua 数学库
- codeforces 2016-2017 NTUWFTSC J Zero Game
- Hibernate中对象的三种状态及相互转化