13368160702mo @ 2024-05-29 16:30:50
#include <iostream>
#include <iomanip>
using namespace std;
bool runnian(int n){
int i=0;
if(n%4==0&&n%100!=0) i=1;
if(n%400==0) i=1;
return (i==1);
}
int main() {
int a,b,js;
cin>>a>>b;
for(int i=a;i<=b;i++){
if(runnian(i)){
js++;
cout<<i<<" ";
}
}
cout<<js;
return 0;
}
by LHM_zs @ 2024-05-29 16:40:55
#include <iostream>
#include <iomanip>
using namespace std;
bool runnian(int n){
int i=0;
if(n%100==0){
if(n%400==0)i=1;
}
else if(n%4==0) i=1;
return (i==1);
}
int main() {
int a,b,js=0;
cin>>a>>b;
for(int i=a;i<=b;i++){
if(runnian(i)){
js++;
}
}
cout<<js<<endl;
for(int i=a;i<=b;i++){
if(runnian(i)){
cout<<i<<" ";
}
}
return 0;
}
@13368160702mo
顺便说一句,js要全局变量
by 13368160702mo @ 2024-05-29 16:46:51
@LHM_zs 谢谢