Pagini recente » Cod sursa (job #108455) | Clasament oni_11_12_8 | Cod sursa (job #3201500) | Cod sursa (job #2466903) | Cod sursa (job #1368454)
program permut;
type p=array[0..10] of longint;
var n,i,j,d,r:longint;t,x:p;f1,f2:text;
begin
assign(f1,'permutari.in');assign(f2,'permutari.out');reset(f1);rewrite(f2);
readln(f1,n); r:=0;
for i:=1 to n do
t[i]:=0; i:=0;
repeat
repeat
i:=i+1;
j:=1;
while t[j]=1 do j:=j+1;
x[i]:=j;
t[j]:=1;
until i=n;
for i:=1 to n do
write(f2,x[i],' ');
writeln(f2);
repeat
t[x[i]]:=0;
x[i]:=0 ;
i:=i-1;
if i<>0 then begin
if x[i]=n then begin t[x[i]]:=0;x[i]:=0;i:=i-1; end;
d:=x[i];
x[i]:=0;
j:=1;
repeat j:=j+1; until ((t[j]=0)and(d<j))or(j>n);
x[i]:=j;
t[j]:=1;
t[d]:=0; end;
until j<=n;
until i=0;
close(f1);close(f2);
end.