Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.
In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.
However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.
Input
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Output
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
Examples
Input
12:21
Output
13:31
Input
23:59
Output
00:00
题目大意:就是让我们求输入时间的下一次成为回文数的时刻。
解析:注意输入时候就是回文不算,题目要求的是下一次,我们可以把小时h和分钟m分开,再将其分成a,b,c,d四个数,a==d&&c==b时候就是回文。
#include <stdio.h>
int pan(int x,int y){ //判断是否回文的自定义函数
int a,b,c,d;
a=x/10,b=x%10,c=y/10,d=y%10;
if(a==d&&b==c) return 1; //是回文返回1,否则返回0
return 0;
}
int main()
{
int h,m;
while(~scanf("%d:%d",&h,&m)){
m++; //避免输入时候就是回文,进不去while,我们先加一次
if(m==60) m=0,h++;
if(h==24) h=0;
while(pan(h,m)==0){
m++;
if(m==60) m=0,h++;
if(h==24) h=0;
}
printf("%02d:%02d\n",h,m); //注意格式
}
return 0;
}