为什么只有40分,大佬们求解答

P5737 【深基7.例3】闰年展示

zhangshudong @ 2022-12-30 12:44:52

#include<iostream>
using namespace std;
int main()
{
    int x, y, num = 0;
    cin >> x >> y;
    for (int i = x; i <= y; i++)
    {
        if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
        {
            num++;
        }
    }
    cout << num << endl;
    for (int i = x; i <= y; i++)
    {
        if (i % 4 == 0 && i % 400 != 0 || i % 400 == 0)
        {
            cout << i<<" ";
        }
    }
    return 0;  
}

by InversionShadow @ 2022-12-30 12:46:30

@zhangshudong 《i % 400 != 0 || i % 400 == 0


by ____someone____ @ 2022-12-30 12:54:43

@zhangshudong

(i % 4 == 0 && i % 100 != 0 || i % 400 == 0) 要用括号把 && 两边的条件括在一起


|