codeforces 816A

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<bits/stdc++.h>
using namespace std;
const int maxn=10;
int a[maxn];
int main()
{
    string s;
    int num1=0,num2=0;
    while(cin>>s)
    {
        memset(a,0,sizeof(a));
        int len=s.length();
        int cnt=0;
        for(int i=0;i<len;i++)
        {
            if(s[i]==':') continue;
            a[cnt++]=s[i]-'0';
        }
        int num=a[0]*10+a[1];
        num1=a[0]+a[1]*10;
        num2=a[2]*10+a[3];
        int sum=0;
        if(num==23&&num2<=32)
        {
            sum=32-num2;
            cout<<sum<<endl;
            continue;
        }
        else if(num==23&&num2>32)
        {
            sum=60-num2;
            cout<<sum<<endl;
            continue;
        }
        else
        {
            while(1)
            {
                if(num2==60)
                {
                    num2=0;
                   if(num1==90)
                   {
                       num1=1;
                   }
                   else if(num1==91)
                   {
                       num1=2;
                   }
                   else
                   {
                       num1+=10;
                   }
                }
                if(num1==num2) break;
                sum++;
                num2++;
            }
            cout<<sum<<endl;
        }
    }
    return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值