求大佬指点,提交仅40分,问题出在哪里了呢?

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

@[Eric20091204](/user/646545) 考虑一下您代码的判断优先级
by Escapism @ 2022-01-21 20:23:23


@[Eric20091204](/user/646545) 您的优先级: ```cpp % 4 == 0 -> % 100 == 0 输出? -> % 400 === 0 输出 ``` 正确的: ```cpp % 4 == 0 -> % 100 == 0 不输出 -> % 100 != 0 输出 % 400 == 0 -> 输出 ```cpp
by Escapism @ 2022-01-21 20:26:53


@[Eric20091204](/user/646545) 因此,您的代码不能只简单地 / 4来求个数
by Escapism @ 2022-01-21 20:34:16


@[Eric20091204](/user/646545) 顺便问问,您是小六的吗
by Escapism @ 2022-01-21 20:50:57


@[112358YC](/user/361505) 谢谢呀
by Programmer_1745 @ 2022-01-22 15:18:02


@[112358YC](/user/361505) 哦吼,是的呢(doge)
by Programmer_1745 @ 2022-01-24 12:40:33


``` #include<bits/stdc++.h> using namespace std; int main() { int x, y, ans = 0; vector<int> v; cin >> x >> y; for (int i = x; i <= y; i++) { if ((i % 4 == 0 && i % 100) || i % 400 == 0) { v.push_back(i); ans++; } } cout << ans << endl; for (auto c: v) cout << c << " "; return 0; } ```
by tyzy_2023 @ 2022-01-31 21:14:51


@[yanhaoyang2106](/user/574849) 谢谢大佬
by Programmer_1745 @ 2022-02-03 20:51:53


```cpp #include<bits/stdc++.h> using namespace std; int main(){ int p,q; cin>>p>>q; int a=p,c=0; for(;a<=q;){ if((a%4==0 && a%100!=0) || a%400==0){ c=c+1; } a=a+1; } cout<<c<<endl; a=p ; for(;a<=q;){ if((a%4==0 && a%100!=0) || a%400==0){ cout<<a<<" "; c=c+1; } a=a+1; } cout<<endl; return 0; } ``` 你用这个试试,应该可以AC。
by limeng911 @ 2022-04-14 22:06:31


|