Cod sursa(job #155952)

Utilizator ral33xstaic raluca ral33x Data 12 martie 2008 11:44:10
Problema Generare de permutari Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.75 kb
type sir=array[1..8]of shortint;
var x:sir;
    n,i,j:shortint;
    f,g:text;
function init(k:integer):integer;
begin init:=0
end;
function urm(k:integer):boolean;
begin urm:=x[k]<n;
      x[k]:=x[k]+1
end;
function ok(k:integer):boolean;
begin
     ok:=true;
     for i:=1 to k-1 do
         if x[k]=x[i] then ok:=false;
end;
procedure tip;
begin
     for i:=1 to n do write(g,x[i],' ');
     writeln(g);
end;
procedure back(k:integer);
begin if k=n+1 then tip
      else begin
           x[k]:=init(k);
           while urm(k)do
                 if ok(k)then back(k+1);
      end
end;
begin assign(f,'permutari.in');reset(f);
      assign(g,'permutari.out');rewrite(g);
      read(f,n);
      back(1);
      close(g)
end.