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 <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
void check(int x, int s[])
{
int k = 0;
while (x)
{
s[k++] = x % 10;
x /= 10;
}
while (k < 2) s[k++] = 0;
}
int main()
{
int a, b;
while (~scanf("%d:%d", &a, &b))
{
for (int i = 0; i < 24 * 60; i++)
{
int ch1[5], ch2[5];
int bb = (b + i) % 60;
int aa = (a + (b + i) / 60)%24;
check(aa, ch1);
check(bb, ch2);
if (ch1[0] == ch2[1] && ch1[1] == ch2[0])
{
printf("%d\n", i); break;
}
}
}
return 0;
}