Codeforces816A Karen and Morning

来源:互联网 发布:创业软件 俞青 编辑:程序博客网 时间:2024/06/18 17:59

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 longconst 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 longconst 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;}