大概是SelectYear函数那里||和&&逻辑混乱
by suyulong1212 @ 2023-11-08 21:52:36
看着是没有啊 @[suyulong1212](/user/275790)
可以把while 换成 for试试
by _____QWQ_____ @ 2023-11-08 21:57:25
```
#include <iostream>
#include <cstring>
using namespace std;
bool SelectYear(int x)
{
if(x % 100 != 0 && x % 4 == 0 || x % 400 == 0){
return true;
}
return false;
}
int main(){
int n,m;
cin>>n>>m;
int a[3000];
int sum=0;
for(int i=n;i<=m;i++)
{
if(SelectYear(i))
{
sum++;
a[sum]=i;
}
}
cout<<sum<<endl;
for(int i=1;i<=sum;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
```
用你的函数ac100过,应该是主函数的问题吧
by _____QWQ_____ @ 2023-11-08 21:59:59
@[______QAQ______](/user/1092781) 那里显然要打括号吧。。。
by suyulong1212 @ 2023-11-08 22:00:12
@[elong123](/user/892700)
试试把所有的main换成boot(你的程序没有大问题,观察细节,或许成功。)
by steven609 @ 2023-11-08 22:01:45
boot main()
by steven609 @ 2023-11-08 22:03:24
@[______QAQ______](/user/1092781) 他用的c呀,c编译器没c++那么聪明
by suyulong1212 @ 2023-11-08 22:04:11
@[______QAQ______](/user/1092781)
感谢我将主函数中的while循环改为for循环就ac了,虽然但是不知道这里错误的原因,大佬...
by elong123 @ 2023-11-08 22:20:48
```
bool SelectYear(int x){
if(x % 100 != 0 && x % 4 == 0 || x % 400 == 0){
return true;
}
return false;
}
int main(){
int x,y;
int sum = 0;
int a[2000];
scanf("%d %d",&x,&y);
// bool s = SelectYear(x);
for(int i = x; i <= y; i++){
if(SelectYear(x)){
a[sum] = x;
sum++;
}
x++;
}
printf("%d\n",sum);
for(int j = 0; j < sum; j++){
printf("%d ",a[j]);
}
return 0;
}
```
这样可以ac了
by elong123 @ 2023-11-08 22:23:14