文章

2

粉丝

56

获赞

0

访问

430

头像
日期计算 题解:为什么测试只通过50%
P1051 中南大学机试题
发布于2024年3月9日 10:16
阅读数 271

#include<iostream>
using namespace std;

struct date {
    int year;
    int month;
    int day;
};

int main() {
    struct date d;
    int f[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    while (cin >> d.year >> d.month >> d.day) {
        if (d.month <= 0 || d.month > 12) {
            cout << "Input error!" << endl;   continue;
        }
        if (d.day <= 0 || d.day > 31) {
            cout << "Input error!" << endl;  continue;
        }
        if (d.year % 100 != 0 && d.year % 4 == 0 || d.year % 400 == 0) {
   &nb...

登录查看完整内容


登录后发布评论

1 条评论
snake
2024年3月9日 11:06

闰年判断的优先级不太对

赞(0)