|
|
back to boardDiscussion of Problem 1068. SumI know why does many people got WA!!!!!!!!!!!! I know why does many people got WA!!!!!!!!!!!! When the n is 0,the result must be 1!!!!!!!!!!!!!! (I'm not from the English-speaking country,my English is very bad.) If there's someting wrong,please tell me,thanks) Thanks i know a better way :-) instead of suming u can use this formula : 1+2+3+...+n := n*(n+1) /2; here is my prog : ioi_khafan@hotmail.com var n : longint; begin read (n); if n = 0 then begin writeln ('1'); exit; end else if n > 0 then n := ( n * (n + 1) ) div 2 else begin n := -1 * n; n := ( n * (n + 1) ) div 2; n := n - 1; n := -1 * n; end; writeln (n); end. Let use shorter Code ! dear voyager Var n :integer; sum :longint; begin readln(n); if n=0 then n:=1; sum:=abs(n)*(abs(n)+1) div 2; if n<0 then sum:=1-sum; writeln(sum); readln; end. Re: I know why does many people got WA!!!!!!!!!!!! Posted by realsy 6 Sep 2005 22:45 Thanks! BTW,I am familiar with your english. Beacuse I can read Chnglish at ZJU. -_-|| Re: I know why does many people got WA!!!!!!!!!!!! Posted by Rasul 20 Oct 2005 23:52 thanks for the help As you see my English too not so ! |
|
|