ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

Please, help! (Wrong Answer, Problem 1068)
Posted by Stupid Petrov 24 Oct 2002 08:05
var
 a, k, b: integer;

begin
 {$IFNDEF ONLINE_JUDGE}
 ASSIGN (input, 'input.txt');
 reset (input);
 assign (output, 'output.txt');;
 rewrite (output);
 {$ENDIF}
 readln (input, a);
 if a>0 then for k:=0 to a do b:=b+k else for k:=1 downto a do b:=b+k;
 writeln (output, b);
 {$IFNDEF ONLINE_JUDGE}
 close (input);
 close (output);
 {$ENDIF}
end.
That
Posted by shitty.Mishka 24 Oct 2002 13:02
> var
>  a, k, b: integer;
>
> begin
>  {$IFNDEF ONLINE_JUDGE}
>  ASSIGN (input, 'input.txt');
>  reset (input);
>  assign (output, 'output.txt');;
>  rewrite (output);
>  {$ENDIF}
>  readln (input, a);
>  if a>0 then for k:=0 to a do b:=b+k else for k:=1 downto a do
b:=b+k;
>  writeln (output, b);
>  {$IFNDEF ONLINE_JUDGE}
>  close (input);
>  close (output);
>  {$ENDIF}
> end.
That's a tuff one ! :) Firstly, use for..to instead of for..downto - it doesn't work properly on timus. And, secondly, variables are not always equal to 0 at the start of program run :) (-)
Posted by shitty.Mishka 24 Oct 2002 13:05