CodeForces - 108A Palindromic Times

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

题意:给出一个xx:xx格式的时间,判断距离这个时间最近的一个回文时间。

一开始打算定义a,b,c,d,然后把所有的可能列一遍,。。。写了一会。。。想不出来orz,然后想把分钟不停的+1,然后判断所得到的时间是不是回文。

#include<stdio.h>
int main()
{
int a,b;
scanf("%d:%d",&a,&b);
while(1)
{
    b++;//时间不停得+1;
    if(b%60==0)加到60,分钟化为0,小时+1;
   {
   	a++;
   	b=b%60;
   }
    int m,n;
    m=a%24;//对小时取模,如果a为24的话,把a变成0
    //n=b%60;
    n=b;
    if(m/10==n%10&&n/10==m%10)判断是否未回文的形式
    {
        printf("%02d:%02d",m,n);//输出的格式要注意一下
        break;
    }
}
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值