Cod sursa(job #316672)

Utilizator madflameAdrian Toncean madflame Data 20 mai 2009 18:49:04
Problema Generare de permutari Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.64 kb
Program Permutari;
Var
 sol: array[1..8] of Byte; n, p: Byte;
 f, g: Text;

Function Valid(k: Byte): Boolean;
Var i: Byte; nok: Boolean;
Begin
 nok:=true;
 i:=1;
 While nok and (i<k) do
  If sol[k] = sol[i] then nok:=false
  Else Inc(i);
 Valid:=nok;
End;

Procedure Back(k: Byte);
Var i, j: Byte;
Begin
 If k = (p+1) then
  Begin For j:=1 to p do Write(g,sol[j],' '); WriteLn(g); End
 Else
  For i:=1 to n do
   Begin
    sol[k]:=i;
    If Valid(k) then Back(k+1);
   End;
End;

BEGIN
 Assign(f,'permutari.in'); Reset(f);
 Assign(g,'permutari.out'); ReWrite(g);
 ReadLn(f,n); p:=n;
 Back(1);
 Close(g);
 Close(f);
END.