program Razbieniya type Razb array byte of byte var byte Razb procedur

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
program Razbieniya;
type Razb=array [byte] of byte;
var N,i,L:byte;
X:Razb;
procedure Next(var X:Razb;var L:byte);
var i,j:byte;
s:word;
begin
i:=L-1;s:=X[L];
{поиск i}
while (i>1)and(X[i-1]<=X[i]) do begin s:=s+X[i];dec(i) end;
inc(X[i]);
L:=i+s-1;
for j:=i+1 to L do X[j]:=1
end;
begin
write('N=');readln(N);
L:=N; for i:=1 to L do X[i]:=1;
for i:=1 to L do write(X[L-i+1]);writeln;
repeat
Next(X,L);
for i:=1 to L do write(X[L-i+1]);writeln
until L=1
end.