Generation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
n, k, i, j: integer;
perm: array[1..15] of integer;
begin
reset(input, 'generation.in');
rewrite(output, 'generation.out');
read(n);
read(k);
for i:= k downto 1 do perm[i]:= i+n-k;
while 1=1 do
begin
for i:= k downto 1 do
begin
write(perm[i]);
write(' ');
end;
writeln;
perm[1]:= perm[1] - 1;
if perm[1] = 0 then
begin
j:= 2;
while perm[j] = j do
begin
j:= j + 1;
end;
perm[j]:= perm[j] - 1;
for i:= j-1 downto 1 do
begin
perm[i]:= perm[i+1] - 1;
end;
if perm[1] < 1 then halt;
end;
end;
{ TODO -oUser -cConsole Main : Insert code here }
end.