#include<bits/stdc++.h>
using namespace std;
int hh,mm,t,s;
int main(){
while(~scanf("%d:%d",&hh,&mm)){
t=hh,s=mm;
while(1){//找上一个回文时刻
s--;
if(s==-1){s=59;t--;}//s==0时,t还没改变,只有减为-1,则置s=59,t减1
if(t==-1)t=23;//t==0时,可以认做24时,实际没有这一时刻,当t==-1时重置t为23时
if(t==(s%10)*10+s/10){printf("%d:%d\n",t,s);break;}
}
t=hh,s=mm;
while(1){//找下一个回文时刻
s++;
if(s==60){s=0;t++;}//当s==60时,重置s=0,同时t加1
if(t==24)t=0;//当t为24时,由于没有24这一时刻,因此此时要重置t为0时
if(t==(s%10)*10+s/10){printf("%d:%d\n",t,s);break;}
}
}
return 0;
}不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。
标签: 简单模拟