Pagini recente » Cod sursa (job #2652166) | Cod sursa (job #1020133) | Cod sursa (job #2645770) | Cod sursa (job #3030942) | Cod sursa (job #2429121)
var t:array[1..10] of integer;
n,k,i,c,p:integer;
procedure tipar;
begin
for i:=1 to n do write(t[i],' ');
writeln
end;
function valid (k:integer):boolean;
begin
c:=0;
for i:=1 to k-1 do
begin
if t[k]=t[i] then inc(c);
if c>0 then break
end;
if c>0 then valid:=false else valid:=true
end;
procedure succ;
begin
if t[k]<n then
begin
inc(t[k]);
p:=1
end
else p:=0
end;
procedure back;
begin
k:=1;
t[k]:=0;
while k>0 do
begin
repeat
succ;
if p>0 then valid(k);
until ((p>0) and (c=0)) or (p=0);
if p>0 then
if k=n then tipar else
begin
inc(k);
t[k]:=0
end
else dec(k)
end
end;
begin
assign(input,'permutari.in'); reset(input);
assign(output,'permutari.out'); rewrite(output);
read(n);
back;
close(input);
close(output)
end.