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 1222. Chernobyl’ Eagles

faint! I don't think there is anything wrong in my code. WHY I GOT WA???
Posted by Hardier 9 Nov 2002 21:48
Program Chernobyl_eagles;
 var
   a:array[0..1000] of integer;
   n,i,k,v:integer;

Begin
  fillchar(a,sizeof(a),0);
  read(n); a[0]:=1;
  if n=1 then begin writeln(1); halt; end;
  if n=2 then begin writeln(2); halt; end;
  if n=3 then begin writeln(3); halt; end;

  if n mod 3=0 then begin n:=n-3; a[1]:=3; end;
  if n mod 3=1 then begin n:=n-4; a[1]:=4; end;
  if n mod 3=2 then begin n:=n-2; a[1]:=2; end;

  k:=n div 3;
  for v:=1 to k do
   begin
     for i:=1 to a[0] do a[i]:=a[i]*3;
     for i:=1 to a[0] do if a[i]>9 then
      begin a[i+1]:=a[i+1]+a[i] div 10; a[i]:=a[i] mod 10; end;
     if a[i+1]>0 then a[0]:=i+1;
   end;
  for i:=a[0] downto 1 do write(chr(ord(a[i])+48)); writeln;
End.
Some tips.
Posted by Leo 20 Nov 2002 13:54
Tip 1:

  if n=1 then begin writeln(1); halt; end;
  if n=2 then begin writeln(2); halt; end;
  if n=3 then begin writeln(3); halt; end;

is equal to

  if (n > 0) and (n < 4) then
  begin
    WriteLn(n);
    exit
  end;

Tip 2:

  write(chr(ord(a[i])+48));

is equal to

  write(a[i]);

Tip 3:

  I think that there is a test with input "0" and output "1".
  Don't ask me why, I don't know.