time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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
#include <stdio.h>
#include <stdlib.h>
int findMin(int arr[],int n){
int index=0;
int i;
for(i=0;i<n;i++){
if(arr[i]<0){
index=i;
break;
}
}
return index;
}
void main(){
char resource[16][5]={
{"00:00"},
{"01:10"},
{"02:20"},
{"03:30"},
{"04:40"},
{"05:50"},
{"10:01"},
{"11:11"},
{"12:21"},
{"13:31"},
{"14:41"},
{"15:51"},
{"20:02"},
{"21:12"},
{"22:22"},
{"23:32"}
};
char time[5];
int i;
int j;
// printf("请输入时间:");
for(i=0;i<5;i++){
scanf(" %c",&time[i]);
}
if(time[0]==time[4]&&time[1]==time[3]){
// printf("它是回文时刻\n");
for(i=0;i<16;i++){
if((resource[i][0]==time[0])&&(resource[i][1]==time[1])){
// printf("它的下一个回文时刻是:");
printf("%c%c%c%c%c",resource[i+1][0],resource[i+1][1],resource[i+1][2],resource[i+1][3],resource[i+1][4]);
break;
}
}
}else{
// printf("它不是回文时刻\n");
int temp[16];
int tempNum=0;
if(time[0]!=time[4]&&time[1]!=time[3]){
for(i=0;i<16;i++){
int h1=(int)time[0]-(int)resource[i][0];
int h2=(int)time[1]-(int)resource[i][1];
int m1=(int)time[3]-(int)resource[i][3];
int m2=(int)time[4]-(int)resource[i][4];
temp[tempNum]=(h1*10+h2)*60+m1*10+m2;
tempNum++;
}
}
int index;
index=findMin(temp,16);
printf("%c%c%c%c%c",resource[index][0],resource[index][1],resource[index][2],resource[index][3],resource[index][4]);
}
}