60分求助c++1,5点不过
查看原帖
60分求助c++1,5点不过
1049171
ymrymr楼主2023/8/11 21:21

真的不知道为啥 第一个点是12月,输出是31天,为啥错

#include <iostream>
using namespace std;
short y, m;
short d[12] { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int main()
{
    cin >> y >> m;
    if(m == 2)
    {
        if(y % 400 == 0)
        {
            cout << "29" << endl;
        }else if(y % 100 == 0)
        {
            cout << "28" << endl;
        }else if(y % 4 == 0)
        {
            cout << "29" << endl;
        }else
        {
            cout << "28" << endl;
        }
        return 0;
    }
    cout << d[m] << endl;
    return 0;
}
2023/8/11 21:21
加载中...