solution.cpp 688 字节
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 <iostream>
using namespace std;
bool is_leap(int year)
{
    return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
int main()
{
    int y, m, d, ans = 0;
    cin >> y >> m >> d;
    int L_m_d[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int nonL_m_d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    if (is_leap(y)) //判断闰年
    {
        for (int i = 0; i < m; i++) //记录1-(m-1)月天数
        {
            ans += L_m_d[i];
        }
        ans += d;
    }
    else
    {
        for (int i = 0; i < m; i++)
        {
            ans += nonL_m_d[i];
        }
        ans += d;
    }
    cout << ans << endl;
    return 0;
}