solution.cpp 643 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include <cstdio>
int month[13][2] = {{0, 0}, {31, 31}, {28, 29}, {31, 31}, {30, 30}, {31, 31}, {30, 30}, {31, 31}, {31, 31}, {30, 30}, {31, 31}, {30, 30}, {31, 31}};

bool isLeap(int year)
{
    return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}

int main()
{
    int y, m, d;
    int count;
    scanf("%d-%d-%d", &y, &m, &d);
    scanf("%d", &count);
    while (count)
    {
        d++;
        if (d > month[m][isLeap(y)])
        {
            d = 1;
            m++;
        }
        if (m > 12)
        {
            m = 1;
            y++;
        }
        count--;
    }
    printf("%d-%d-%d", y, m, d);
    return 0;
}