Cod sursa(job #636931)
Utilizator | Data | 20 noiembrie 2011 02:40:14 | |
---|---|---|---|
Problema | Combinari | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 1.52 kb |
program combinari;
type sir=array[0..18] of byte;
var i,j,p,n,k:byte;
o,d:text;
s:sir;
function valid(j:byte):boolean;
begin
valid:=true;
if s[j-1]>s[j] then valid:=false
else for p:=1 to j-1 do
if s[p]=s[j] then
begin
valid:=false;
break;
end;
end;
procedure output(a:sir);
begin
for p:=1 to k do write(o,s[p],' ');
writeln(o,'');
end;
begin
assign(d,'combinari.in');
assign(o,'combinari.out');
reset(d);rewrite(o);
read(d,n);read(d,k);
i:=1;
while i<>0 do
begin
s[i]:=s[i]+1;
if valid(i) then if s[i]>n then
begin
s[i]:=0;
i:=i-1;
end
else if i=k then
begin
output(s);
if s[i]=n then
begin
s[i]:=0;
i:=i-1;
end;
end
else i:=i+1;
end;
close(d);close(o);
end.