为啥还是零分 测试多次都能通过

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

jifeng85 @ 2020-10-20 18:55:35

#include<iostream>
using namespace std;
int main()
{
    int x , y = 0;
    int arr[1000];
    cin >> x >> y;
    int j = 0;
    for (int i=0;x <= y;x++) 
    {
        if (x % 400 == 0) 
        {
            arr[i] = x;
            i++;
            j++;
        }
        else if (x % 100 != 0 && x % 4 == 0)
        {
            arr[i] = x;
            i++;
            j++;
        }
        else { continue; }
    }
    cout << j << endl;
    for (int q = 0;q < 1000;q++)
    { if (arr[q]>0)
        cout << arr[q] << " ";
    else { continue; }
    }
}

望大佬们不吝赐教


by 159号程序员 @ 2020-10-20 18:57:50

@jifeng85 测下样例ok?


by 159号程序员 @ 2020-10-20 18:58:40

你这个arr数组需要定义成全局的啊,要不然不会给你设初始值的


by 159号程序员 @ 2020-10-20 18:58:55

本地过了可能是编译器问题


by 江南才子一枚 @ 2020-10-20 19:19:08

arr没memset


by jifeng85 @ 2020-10-21 09:57:03

@159号程序员 感谢 了解了


by jifeng85 @ 2020-10-21 09:59:46

@159号程序员 太感谢了 已经通过了


by Tianxn @ 2021-01-09 16:10:40

#include <iostream>
using namespace std;

int a, b, cnt = 0;
int leap[1500];

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

int main() {
    cin >> a >> b;
    for (int i = a; i <= b; ++i)
        if (isLeap(i)) leap[cnt++] = i;
    cout << cnt << endl;
    for (int i = 0; i < cnt; ++i)
        cout << leap[i] << " ";
    return 0;
} 

|