求简化!

P5737 【深基7.例3】闰年展示

@[lvhaoyang9](/user/638744) 你可以用数组啊
by Escapism @ 2022-02-03 21:51:17


```cpp #include<iostream> #include<cstdio> using namespace std; int x,y,s1,s2; int year[10000]; void rn1(int a,int b){ for(int i=a;i<=b;i++){ if(i%4==0&&i%100!=0||i%400==0) { s1++; year[s1] = i; } } cout<<s1<<endl; for (int i = 1;i <= s1;i++) cout<<year[i]<<" "; } int main(){ cin>>x>>y; rn1(x,y); return 0; } ```
by Escapism @ 2022-02-03 21:54:53


用数组干啥? ```cpp #include <bits/stdc++.h> using namespace std; int main() { int x, y, sum=0;; cin >> x >> y; for (int i = x; i <= y; i ++ ) if(i % 400 == 0 || i % 4 == 0 && i % 100 != 0) sum++; cout << sum << endl; for (int i = x; i <= y; i ++ ) if(i % 400 == 0 || i % 4 == 0 && i % 100 != 0) cout << i << " "; cout << endl; return 0; } ```
by 违规用户名ddc277a @ 2022-03-21 19:35:29


|