zoukankan      html  css  js  c++  java
  • codeforces round #419 A. Karen and Morning

    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  ≤ 23, 00 ≤  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.

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 char s[12];int n;
     7 bool check()
     8 {
     9     int l=1,r=n;
    10     while(l<r)
    11     {
    12         if(s[l]!=s[r])return false;
    13         l++;r--;
    14     }
    15     return true;
    16 }
    17 int main()
    18 {
    19     scanf("%s",s+1);
    20     n=strlen(s+1);
    21     int ans=0;
    22     while(1)
    23     {
    24         if(check())
    25         {
    26             printf("%d",ans);
    27             return 0;
    28         }
    29         s[5]++;ans++;
    30         if(s[5]=='9'+1)s[5]='0',s[4]++;
    31         if(s[4]=='6')s[4]='0',s[2]++;
    32         if(s[2]=='9'+1 && s[1]<='1')s[1]++,s[2]='0';
    33         if(s[2]=='4' && s[1]=='2')s[1]='0',s[2]='0';
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    谁是你随时可以说话的人
    我们在帝都这么拼,为的是什么?
    CVE-2016-4758: UXSS in Safari's showModalDialog
    JSON-SCHEMA
    JS城市data
    linux(centos )mongodb install
    python pip install
    基于chrome内核的UXSS
    Trying to hack Redis via HTTP requests
    Apache Solr 访问权限控制
  • 原文地址:https://www.cnblogs.com/Yuzao/p/7044051.html
Copyright © 2011-2022 走看看