20分求助 +1

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

LHX_18460366315 @ 2024-02-03 18:13:34

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,n = 0,num[1000000];
    cin >> a >> b;
    for (long long i = a;i <= b;i++){
        if ((i % 400 == 0) || (i % 4 == 0 && i % 100 != 0)){
            n++;
            num[n] = i;
        }
    }
    cout << n << endl;
    for (long long i = 0;i < n;i++){
        cout << num[i] << " ";
    }
}

by Li_Feiy @ 2024-02-03 18:23:40

@ZZYX_18670145320

#include<bits/stdc++.h>
using namespace std;
long long a,b,n = 0,num[1000000];
int main(){

    cin >> a >> b;
    for (long long i = a;i <= b;i++){
        if ((i % 400 == 0) || (i % 4 == 0 && i % 100 != 0)){
            n++;
            num[n] = i;
        }
    }
    cout << n << endl;
    for (long long i = 1;i <= n;i++){
        cout << num[i] << " ";
    }
}

by Li_Feiy @ 2024-02-03 18:24:39

@ZZYX_18670145320 数组过大要放main函数外面,n是从1开始记录的


by LHX_18460366315 @ 2024-02-03 18:25:58

@Li_Feiy 哦,谢谢


|