Cod sursa(job #175017)
Utilizator | Data | 9 aprilie 2008 14:51:36 | |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 1.02 kb |
var s:array[1..10] of longint;
n:longint;
procedure back(l:longint);
var i,j:longint;
ok:boolean;
begin
if n=l then
begin
for i:=1 to l do write(s[i],' ');
writeln;
end
else
begin
for i:=1 to n do
begin
ok:=true; j:=1;
while(j<=l)and(ok) do
begin
if s[j]=i then ok:=false;
inc(j);
end;
if ok then
begin
s[l+1]:=i;
back(l+1);
end;
end;
end;
end;
begin
assign(input,'permutari.in'); reset(input);
assign(output,'permutari.out'); rewrite(output);
readln(n);
back(0);
close(input); close(output);
end.