lyc_77777 @ 2024-08-06 18:03:13
#include <iostream>
using namespace std;
int main()
{
int x,y;
int a = 0;
int b[100];
cin >> x >> y;
for (int i = x; i <= y; i++)
{
if (i % 4 == 0&&i%100!=0||i%400==0)
{
b[a] = i;
a++;
}
}
cout << a << endl;
for(int i = 0;i<a;i++)
{
cout << b[i] << ' ';
}
return 0;
}
by LRRabcd @ 2024-08-06 18:08:51
#include <iostream>
using namespace std;
int main()
{
int x,y;
int a = 0;
int b[2005];
cin >> x >> y;
for (int i = x; i <= y; i++)
{
if (i % 4 == 0&&i%100!=0||i%400==0)
{
b[a] = i;
a++;
}
}
cout << a << endl;
for(int i = 0;i<a;i++)
{
cout << b[i] << ' ';
}
return 0;
}
by LRRabcd @ 2024-08-06 18:09:16
b数组开大一点
by yangzijin @ 2024-08-20 21:41:46
#include<bits/stdc++.h>
using namespace std;
bool f(long long i){
if(i%4==0&&i%100!=0||i%400==0)return true;
return false;
}
int main(){
int sum=0;
long long a,b;
cin>>a>>b;
for(long long i=a;i<=b;i++){
if(f(i))sum++;
}
cout<<sum<<endl;
for(long long i=a;i<=b;i++){
if(f(i))cout<<i<<' ';
}
return 0;
}
@lyc_77777 AC代码