Cod sursa(job #240872)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 8 ianuarie 2009 20:42:33
Problema Combinari Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.99 kb
program alex;
var st:array[0..100]of integer;
    f:text;
    j,i,n,k:integer;
    as,ev:boolean;
begin
assign(f,'combinari.in');reset(f);
readln(f,n,k);
close(f);
j:=1;
st[j]:=0;
assign(f,'combinari.out');rewrite(f);
while j>0 do
      begin
      repeat
      if st[j]<n then begin
                      st[j]:=st[j]+1;
                      as:=true;
                      end
                 else as:=false;
      if as then begin
                 ev:=true;
                 if st[j-1]>=st[j] then ev:=false;
                 end;
      until(not as)or (as and ev);
      if as then if j=k then begin
                             for i:=1 to j do
                                 write(f,st[i],' ');
                             writeln(f);
                             end
                        else begin
                             j:=j+1;
                             st[j]:=0;
                             end
             else j:=j-1;
      end;
close(f);
end.