8-P-10

#include<stdio.h>

int main(void)
{
    int hour, minute, time, d;
    int start_hour[8] = { 8 * 60, 9 * 60 + 43,11 * 60 + 19 ,12 * 60 + 47 ,14 * 60,15 * 60 + 45, 19 * 50 ,21 * 60 + 45 };

    printf("Please enter a 24-hour time:");
    scanf_s("%d:%d", &hour, &minute);
    time = hour * 60 + minute;

    if (time <= (start_hour[0] + start_hour[1]) / 2)
    {
        d = start_hour[0];
    }
    else if (time <= (start_hour[1] + start_hour[2]) / 2)
    {
        d = start_hour[1];
    }
    else if (time <= (start_hour[2] + start_hour[3]) / 2)
    {
        d = start_hour[2];
    }
    else if (time <= (start_hour[3] + start_hour[4]) / 2)
    {
        d = start_hour[3];
    }
    else if (time <= (start_hour[4] + start_hour[5]) / 2)
    {
        d = start_hour[4];
    }
    else if (time <= (start_hour[5] + start_hour[6]) / 2)
    {
        d = start_hour[5];
    }
    else if (time <= (start_hour[6] + start_hour[7]) / 2)
    {
        d = start_hour[6];
    }
    else if (time > (start_hour[6] + start_hour[7]) / 2 && time < start_hour[7])
    {
        d = start_hour[7];
    }
    else
    {
        d = start_hour[0];
    }

    if (d <= 780)
    {
        printf("Closest departrue time is %d:%d a.m.", d / 60, d % 60);
    }
    else
    {
        printf("Closest departrue time is %d:%d p.m.", (d / 60) - 12, d % 60);
    }

    return 0;
}

上一篇:May LeetCoding Challenge 之 异或运算


下一篇:Qt 获取年、月、日、时、分、秒