Cod sursa(job #546295)

Utilizator ion_calimanUAIC Ion Caliman ion_caliman Data 4 martie 2011 18:55:30
Problema Loto Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.71 kb
var     a,v:array[1..100] of longint;
        n,i:integer;
        s:longint;
        f1,f2:text;
        b:boolean;

procedure loto(p:integer; s1:longint);
var     i:integer;
begin
  if p=6 then begin
      if s1=s then
    begin
      for i:=1 to 6 do
        write(f2,v[i],' ');
      close(f2);
      halt;
    end
    end
  else
    for i:=1 to n do
      begin
        v[p+1]:=a[i];
        loto(p+1,s1+a[i]);
      end;
end;

begin
  assign(f1,'loto.in');
  assign(f2,'loto.out');
  reset(f1);
  rewrite(f2);
  readln(f1,n,s);
  for i:=1 to n do
    read(f1,a[i]);

  for i:=1 to n do
    begin
      v[1]:=a[i];
      loto(1,a[i]);
    end;

  writeln(f2,-1);
  close(f2);
end.