lzj20110120 @ 2023-11-26 15:47:25
样例过了,可还是WA了。 代码如下:(c++)
#include<bits/stdc++.h>
using namespace std;
int s,e,sum,y[10000],ysum,year=0,a=0;
int main()
{
cin>>s>>e;
ysum=e-s;
year=s+1;
for(int i=0;i<ysum;i++)
{
if(year%400==0)
{
sum++;
y[i]=year;
}
else
{
if(year%4==0&&year%100!=0)
{
sum++;
y[i]=year;
}
}
year++;
a++;
}
cout<<sum<<endl;
for(int i=0;i<ysum;i++)
{
cout<<y[i]<<' ';
}
}
求大佬指点指点,蟹蟹!QWQ
by litchi36 @ 2023-11-26 15:57:01
@lzj20110120
你看这个有问题
by litchi36 @ 2023-11-26 16:06:47
@lzj20110120 错误的原因在于如果这一年不是闰年你的这个y[计数变量]=year
,然后让计数变量增加
by chengyilin @ 2023-11-26 16:11:02
#include<bits/stdc++.h>
using namespace std;
int s,e,sum,y[10000],ysum,year=0,a=0;
int main(){
cin>>s>>e;
ysum=e-s+1;
year=s;
for(int i=0;i<ysum;i++){
if(year%400==0){
y[sum]=year;
sum++;
}
else{
if(year%4==0&&year%100!=0){
y[sum]=year;
sum++;
}
}
year++;
}
cout<<sum<<endl;
for(int i=0;i<sum;i++){
cout<<y[i]<<' ';
}
}
by lzj20110120 @ 2023-11-29 19:20:16
@hawstrip 感谢debug