## 【CodeForces-816A】Karen and Morning【进制+暴力+栈】

【CodeForces-816A】Karen and Morning【进制+暴力+栈】

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.

Input:

The first and only line of input contains a single string in the format hh:mm (00 ≤ hh  ≤ 2300 ≤  mm  ≤ 59).

Output:

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.

Solution:

```#include <stdio.h>

int stack[2];
int isPalindrome(int h, int m) {
int pos = 0;
int cx = 2;
while (cx--) {
stack[pos++] = h % 10;
h /= 10;
}
while(pos--) {
if (stack[pos] != m % 10) return 0;
m /= 10;
}
return 1;
}

int main(void) {
int h, m;
int lim = 24 * 60;
scanf("%d:%d", &h, &m);
for (int cnt = h * 60 + m; true; cnt++) {
if (cnt >= lim) cnt %= lim;
if (isPalindrome(cnt / 60, cnt % 60)) {
printf("%d\n", ((cnt - h * 60 - m) % lim + lim) % lim);
break;
}
}
return 0;
}
```