zoukankan      html  css  js  c++  java
  • A. Karen and Morning(Round419)

    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, because05: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.

     hint:给你一个时间,让你求这个时间到下一个回文时间需要多久。。。

    这个题目,我刚开始还真是想着去把所有的回文数字给找出来,然后挨个判断,结果可想而知啊。。吃力不讨好。。。

    看完题解之后,我发现。。。是不是div2的前几题都是可以大力出奇迹的题。。。

    所以这个题目就是大力搞一发好了。。。将所给时间加1加1这样迭代加下去直到它成为一个回文数字。。。因为一天也就是24*60*3600s 。。。怎么暴力都不会超时的。。。

    #include<iostream>
    #include<cstdio>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<cmath>
    #include<cstring>
    #include<stdlib.h>
    #include<algorithm>
    using namespace std;
    #define pb push_back
    #define mk make_pair
    #define FOR(i, a, b) for(int i=a; i<=b; i++)
    #define FO(i, a, b) for(int i=a; i<b; i++)
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define eps 1e-8
    #define mem(a, b) memset(a, b, sizeof(a))
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    
    int main(){
        int hh, mm;
        scanf("%d:%d", &hh, &mm);
        int cnt = 0;
        while(1){
            if(hh%10*10+hh/10 == mm) break;
            if(mm == 59){           //在几个特殊的地方要判断一下,比如分钟为59的时候,小时为23的时候。。。
                cnt++;
                mm = 0;
                if(hh != 23) hh++;
                else hh = 0;
            }else{
                mm++;
                cnt++;
            }
        }
        printf("%d
    ", cnt);
        return 0;
    }
  • 相关阅读:
    DevExpress中的gridControl选择问题
    使用IL DASM来查看接口内的自动属性
    多态的使用 虚方法、抽象类、接口
    匿名类的使用及原理
    JAVA小问题解决办法
    数据库02
    数据库01(验证连接是否成功)
    Java 类库知识总结
    Java多线程知识总结(补充)
    java Thread和Runable的深刻理解
  • 原文地址:https://www.cnblogs.com/ledoc/p/7126676.html
Copyright © 2011-2022 走看看