评测机有问题,还是判奇数有问题?

P1348 Couple number

ans没有初始化为0
by FlowNews @ 2019-07-20 17:43:29


@[zhaowangji](/space/show?uid=164840) ~~你的程序有问题~~
by FlowNews @ 2019-07-20 17:45:33


@[刘谅闻](/space/show?uid=217795) 定义在主程序外。。。。
by zhaowangji @ 2019-07-20 17:54:42


@[刘谅闻](/space/show?uid=217795) 能不能看好了。。。
by zhaowangji @ 2019-07-20 17:55:27


有负数,负数%2可能为-1
by swiftc @ 2019-07-20 18:01:58


@[zhaowangji](/space/show?uid=164840)
by swiftc @ 2019-07-20 18:02:31


```cpp #include<bits/stdc++.h> using namespace std; int main(){ int a,b,ans=0; cin>>a>>b; for(int i=a;i<=b;i++){ if(i%4==0||i%2==1||i%2==-1)ans++; } cout<<ans<<endl; return 0; } ``` 这就对了
by swiftc @ 2019-07-20 18:03:23


第一个测试点的输入: -99999 10
by 糪眾脦颰罷 @ 2019-07-20 18:03:27


而且-1%2=-1
by 糪眾脦颰罷 @ 2019-07-20 18:04:10


会出现负数
by lyb666666 @ 2019-07-20 18:05:14


| 下一页