Pagini recente » Cod sursa (job #415475) | Cod sursa (job #1240546) | Cod sursa (job #956714) | Cod sursa (job #40941) | Cod sursa (job #155952)
Cod sursa(job #155952)
type sir=array[1..8]of shortint;
var x:sir;
n,i,j:shortint;
f,g:text;
function init(k:integer):integer;
begin init:=0
end;
function urm(k:integer):boolean;
begin urm:=x[k]<n;
x[k]:=x[k]+1
end;
function ok(k:integer):boolean;
begin
ok:=true;
for i:=1 to k-1 do
if x[k]=x[i] then ok:=false;
end;
procedure tip;
begin
for i:=1 to n do write(g,x[i],' ');
writeln(g);
end;
procedure back(k:integer);
begin if k=n+1 then tip
else begin
x[k]:=init(k);
while urm(k)do
if ok(k)then back(k+1);
end
end;
begin assign(f,'permutari.in');reset(f);
assign(g,'permutari.out');rewrite(g);
read(f,n);
back(1);
close(g)
end.