CodeForces-816A A - Karen and Morning 思维

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37753409/article/details/83473105

CodeForces-816A A - Karen and Morning

题意: 给定一个时间格式为 小时:分钟 判断到下一个回文时间所需要的分钟数.
分析: 每个小时只会对应一个回文时间(有些没有), 打表出每一个对应的回文时间, 然后从当前实践计算即可.
代码:

#include <iostream>
#include <cstdio>

using namespace std;

int tim[] = {
    0, 10, 20, 30, 40, 50, -1, -1, -1, -1, 1, 11, 21, 31, 41, 51, -1, -1, -1, -1, 2, 12, 22, 32, 0, 10, 20
};

int main ()
{
    int a, b;
    scanf ("%d:%d", &a, &b);
    int t = 0;
    int p = tim[a];
    if (b == p) printf ("0\n");
    else if (b < p) printf ("%d\n", p - b);
    else
    {
        int i = a;
        for (i = a + 1; i < 26; i++)
            if (tim[i] != -1) 
                break;
        p = tim[i];
        int sum = (i - a)*60 + p - b;
        printf ("%d\n", sum);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37753409/article/details/83473105