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

where is wrong!
Posted by girl 29 Oct 2002 11:01
why my program is wrong!
var n,j,i:integer;
    a:array[1..2000] of integer;
procedure cheng(x:integer);
var i,g:integer;
begin
  for i:=1 to 2000 do
    a[i]:=a[i]*x;
  for i:=1 to 2000 do
  begin
    g:=a[i] div 10;
    a[i+1]:=a[i+1]+g;
    a[i]:=a[i] mod 10;
  end;
end;
begin
  read(n);
  if n<4 then
  begin
    writeln(n);
    halt;
  end;
  fillchar(a,sizeof(a),0);
  if n>=3 then
  begin
    a[1]:=3;
    n:=n-3;
  end;
  while n-3>=0 do
  begin
    n:=n-3;
    cheng(3);
  end;
  if n<>0 then cheng(n);
  i:=2000;
  while (i>1) and (a[i]=0) do dec(i);
  for j:=i downto 1 do
    write(chr((ord(a[j])+48)));
end.
Chang "read" to "readln" but it got WA too. I don't no why
Posted by I am david. Tabo. 29 Oct 2002 11:26
> why my program is wrong!
> var n,j,i:integer;
>     a:array[1..2000] of integer;
> procedure cheng(x:integer);
> var i,g:integer;
> begin
>   for i:=1 to 2000 do
>     a[i]:=a[i]*x;
>   for i:=1 to 2000 do
>   begin
>     g:=a[i] div 10;
>     a[i+1]:=a[i+1]+g;
>     a[i]:=a[i] mod 10;
>   end;
> end;
> begin
>   readln(n);
>   if n<4 then
>   begin
>     writeln(n);
>     halt;
>   end;
>   fillchar(a,sizeof(a),0);
>   if n>=3 then
>   begin
>     a[1]:=3;
>     n:=n-3;
>   end;
>   while n-3>=0 do
>   begin
>     n:=n-3;
>     cheng(3);
>   end;
>   if n<>0 then cheng(n);
>   i:=2000;
>   while (i>1) and (a[i]=0) do dec(i);
>   for j:=i downto 1 do
>     write(chr((ord(a[j])+48)));
> end.
>
I don't know but...
Posted by Leo 20 Nov 2002 14:02
Tip:
  write(chr((ord(a[j])+48)));
is equal to
  write(a[j]);