|
|
back to boardDiscussion of Problem 1068. SumWhy wrong (c) #include <stdio.h> #include <math.h> int plus(int number){ return number*(number+1)/2; } int minus(int number){ return (-(number*(number+1)/2))+number; } int main(){ int N; scanf("%d",&N); if(abs(N)>=1 && abs(N)<=10000){ if(N<0) printf("%d",minus(N)); else printf("%d",plus(N)); } } Re: Why wrong (c) Posted by Orient 2 Mar 2018 23:10 Why do you think, that 0 is prohibited input? What the reason to check input at all? "if(abs(N)>=1 && abs(N)<=10000)" is superfluous. The statement of the problem can't lie. Re: Why wrong (c) Posted by Orient 2 Mar 2018 23:12 Also minus() is wrong. Re: Why wrong (c) Thanks you so much. I'm new to olympiad programming and I sometimes make silly mistakes thanks to pointing to them Re: Why wrong (c) Edited by author 03.03.2018 09:54 No subject Edited by author 03.03.2018 09:53 |
|
|