Pagini recente » Cod sursa (job #1534000) | Cod sursa (job #1395203) | Cod sursa (job #1238522) | Cod sursa (job #681286) | Cod sursa (job #316672)
Cod sursa(job #316672)
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.