Lindafish @ 2024-01-30 22:38:41
#include <stdio.h>
int main()
{
int x,y;
scanf("%d %d",&x,&y);
int i=x,year=x;
int count=0;
for (i=x;i<=y;i++){
if ((i%4==0&&x%100!=0)||(x%100==0&&x%400==0)){
count++;
}
}
printf("%d",count);
for (year=x;year<=y;year++){
if ((year%4==0&&year%100!=0)||(year%100==0&&year%400==0)){
printf("%d",year);
}
}
return 0;
}
by penguin_is_cool @ 2024-01-30 22:43:50
@Lindafish 第十行:if((i%4==0&&x%100!=0)
应该是i%100!=0吧
by penguin_is_cool @ 2024-01-30 22:44:18
@Lindafish 第二个判断也是
by penguin_is_cool @ 2024-01-30 22:46:39
@Lindafish 你还忘了输出换行和空格 修改后AC代码:
#include <stdio.h>
int main()
{
int x,y;
scanf("%d %d",&x,&y);
int i=x,year=x;
int count=0;
for (i=x;i<=y;i++){
if ((i%4==0&&i%100!=0)||(i%100==0&&i%400==0)){
count++;
}
}
printf("%d\n",count);
for (year=x;year<=y;year++){
if ((year%4==0&&year%100!=0)||(year%100==0&&year%400==0)){
printf("%d ",year);
}
}
return 0;
}
by Lindafish @ 2024-01-30 22:58:52
@penguin_is_cool 哇哇哇,太感谢大佬连续回我两个求助贴了(✧◡✧)