Codeforces816A Karen and Morning

A. Karen and Morning
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

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.

Examples
input
05:39
output
11
input
13:31
output
0
input
23:59
output
1
Note

In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.

In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.

In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.


————————————————————————————————

题目的意思是给你一个时间,问过了多少时间才会让现在时间变成回文

模拟时间流逝 每一秒判一次是否回文

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define LL long long
const int inf=0x7fffffff;

bool check(int h,int m)
{
    if(h/10+(h%10)*10==m)
        return 1;
    return 0;
}
int main()
{
   int h,m;
   while(~scanf("%d:%d",&h,&m))
   {
       int ans=0;
       while(!check(h,m))
       {
           ans++;
           m++;
           if(m==60)
            h+=1,m=0;
           if(h==24)
            h=0;
       }
       printf("%d\n",ans);


   }

    return 0;
}

或者干脆蠢一点根据时间分类讨论

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define LL long long
const int inf=0x7fffffff;

int main()
{
    int h,m;
    while(~scanf("%d:%d",&h,&m))
    {
        int t=h*60+m;
        int ans;
        if(h<5||(h==5&&m<=50))
        {
            int fm=h*10;
            if(m<=fm)
            {
                ans=fm-m;
            }
            else
            {
                fm=(h+1)*10;
                ans=(h+1)*60+fm-t;
            }
        }
        else if(h<=9)
        {
            ans=10*60+1-t;
        }
        else if(h<15||(h==15&&m<=51))
        {
            int fm=(h%10)*10+(h/10);
            if(m<=fm)
            {
                ans=fm-m;
            }
            else
            {
                fm=((h+1)%10)*10+((h+1)/10);
                ans=(h+1)*60+fm-t;
            }
        }
        else if(h<=19)
        {
            ans=20*60+2-t;
        }
        else if(h<23||(h==23&&m<=32))
        {
            int fm=(h%10)*10+(h/10);
            if(m<=fm)
            {
                ans=fm-m;
            }
            else
            {
                fm=((h+1)%10)*10+((h+1)/10);
                ans=(h+1)*60+fm-t;
            }
        }
        else
        {
            ans=24*60-t;
        }
        printf("%d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值