Cod sursa(job #68532)

Utilizator svalentinValentin Stanciu svalentin Data 28 iunie 2007 12:29:24
Problema Sarpe Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.89 kb
var i,n,jpr,t,o,aux:longint;
    ch:string[1];
    b,a:array[1..1500] of shortint;
    l:integer;

procedure inmultire;
var ipr:longint;
begin
for ipr:=n downto 1 do
  begin
   inc(o);
   b[o]:=(8*a[ipr]+t) mod 10;
   t:=(8*a[ipr]+t) div 10;
  end;
while t<>0 do
  begin
   inc(o);
   b[o]:=t mod 10;
   t:=t div 10;
  end;
end;

begin
  assign(input,'sarpe.in');
  assign(output,'sarpe.out');
  reset(input);
  rewrite(output);
  while (not eof) and (not eoln) do
  begin
    read(ch);
    inc(n);
    val(ch,a[n],l);
  end;
  if (a[n]=1) and (n=1) then
  begin
    write(2);
    halt;
  end;
  if a[n]=0 then
  begin
    aux:=n;
    while a[aux]=0 do
      dec(aux);
    dec(a[aux]);
    for jpr:=aux+1 to n do
      a[jpr]:=9;
  end
  else
    a[n]:=a[n]-1;

  inmultire;
  for i:=o downto 1 do
    write(b[i]);
  close(input);
  close(output);
end.