Cod sursa(job #153618)

Utilizator hitmannCiocas Radu hitmann Data 10 martie 2008 17:18:30
Problema Combinari Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 1.02 kb
program combinari;
var st:array[1..20]of integer;
    n,k,c,i:integer;
    g:text;
    as,ev:boolean;
procedure citire;
var f:text;
begin assign(f,'combinari.in'); reset(f);
read(f,n,c);
close(f);
end;
procedure succesor;
begin
if st[k]<n then begin
                inc(st[k]);
                as:=true;
                end
           else as:=false;
end;
procedure valid;
begin
ev:=true;
if k>=2 then
     begin
     if st[k-1]>=st[k] then ev:=false;
     i:=1;
     while ev and(i<=k-1) do
      begin
      if st[i]=st[k] then ev:=false;
      inc(i);
      end;
     end;
end;
begin {pp}
citire;
assign(g,'combinari.out'); rewrite(g);
k:=1;
while k>0 do
begin
 repeat
 succesor;
 if as then valid;
 until not as or (as and ev);
 if as then if k=c then begin
                        for i:=1 to k do write(g,st[i],' ');
                        writeln(g);
                        end
                   else begin inc(k); st[k]:=0; end
       else dec(k);
 end;
close(g);
end.