求助

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

```cpp #include <iostream> using namespace std; int main() { int x,y; int a = 0; int b[2005]; cin >> x >> y; for (int i = x; i <= y; i++) { if (i % 4 == 0&&i%100!=0||i%400==0) { b[a] = i; a++; } } cout << a << endl; for(int i = 0;i<a;i++) { cout << b[i] << ' '; } return 0; } ```
by 20121028LRR @ 2024-08-06 18:08:51


b数组开大一点
by 20121028LRR @ 2024-08-06 18:09:16


``` #include<bits/stdc++.h> using namespace std; bool f(long long i){ if(i%4==0&&i%100!=0||i%400==0)return true; return false; } int main(){ int sum=0; long long a,b; cin>>a>>b; for(long long i=a;i<=b;i++){ if(f(i))sum++; } cout<<sum<<endl; for(long long i=a;i<=b;i++){ if(f(i))cout<<i<<' '; } return 0; } ``` @[lyc_77777](/user/1398944) AC代码
by yangzijin @ 2024-08-20 21:41:46


|