wu_wowo @ 2020-10-06 17:16:38
#include<iostream>
using namespace std;
int main(){
int m,c,num=0,shu[1500];
cin>>m>>c;
for(int a=m ;a<=c;a++){
if(a%4==0&&a%100!=0){
shu[num ]=a;
num++;
}
else{
if(a%400==0){
shu[num ]=a;
num++;
}
}
}
cout<<num<<'\n';
for(int i=0;i<=num ;i++){
cout<<shu[i]<<" ";
}
return 0;
}
by Miraclezzz @ 2020-10-12 16:19:27
您最后的循环里面应该 i<num
by 听取AC声一片 @ 2020-10-14 13:26:47
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,y,sum=0;
cin>>a>>y;
for(int x=a;x<=y;x++)
{
if(x%4==0)
{
if(x%100==0)
{
if(x%400==0)
{
sum++;
}
else
continue;
}
else
sum++;
}
else
continue;
}
cout<<sum<<endl;
for(int x=a;x<=y;x++)
{
if(x%4==0)
{
if(x%100==0)
{
if(x%400==0)
{
cout<<x<<" ";
}
else
continue;
}
else
cout<<x<<" ";
}
else
continue;
}
return 0;
}
我的代码(AC)
by 听取AC声一片 @ 2020-10-14 13:27:37
这样就很容易理解
by wu_wowo @ 2020-10-16 21:15:23
@Hazers 蟹蟹
by Blood_red @ 2021-02-16 18:36:26
#include <bits/stdc++.h>
using namespace std;
int a[1500];
bool r(int y){
return y%100!=0&&y%4==0||y%400==0;
}
int main(){
int x,y,k=0;
cin>>x>>y;
for(int i=x;i<=y;++i)
if(r(i))
a[k++]=i;
cout<<k<<endl;
for(int i=0;i<k;++i)
cout<<a[i]<<' ';
cout<<endl;
return 0;
}
C++
by 国家级白嫖 @ 2021-03-26 00:34:38
#include <iostream>
using namespace std;
int main()
{
int x,y,sum=0;
cin>>x>>y;
int a[1500];
for(int i=x;i<=y;i++)
{
if((i%100!=0&&i%4==0)||(i%400==0))
{ sum+=1;
a[sum]=i;
}
}
cout<<sum<<endl;
for(int j=1;j<=sum;j++)
{
cout<<a[j]<<" ";
}
return 0;
}
来水一下(doge)