uses Crt;

const Maxbilder = 100; {max. Zahl an Bilder pro Album}
      Minbilder = 30;  {min Zahl an Bilder pro Album}
      Minpack   = 1;   {min Zahl an Bildern pro P„ckchen}
      Maxpack   = 7;

var Album : array [1..Maxbilder] of Integer;
    Albumsize : Integer;
    Packsize  : Integer;
    Packcount : Integer;
    Min,Max   : Integer;
    Mittel    : Double;
    Laeufe    : Integer;

procedure Eingabe;

begin
  repeat
    Write('Anzahl an Bildern pro Album : ');
    Read(Albumsize);
  until Albumsize in [Minbilder..Maxbilder];
  WriteLn;
  repeat
    Write('Anzahl an Bildern pro P„ckchen : ');
    Read(Packsize);
  until Packsize in [Minpack..Maxpack];
  WriteLn;
  Write('Wieviele L„ufe : ');
  Read(Laeufe);
end;

procedure Simulation;

var Fertig : Boolean;
    I,Nr   : Integer;

procedure Init;

var I      : Integer;

begin
  for I:=1 to Albumsize do Album[I]:=0;
  Packcount:=0;
  Randomize;
end;

begin
  Init;
  repeat
    for I:=1 to Packsize do
    begin
      Nr:=Random(Albumsize)+1;
      Album[Nr]:=Album[Nr]+1;
    end;
    Inc(Packcount);
    Fertig:=True;
    for I:=1 to Albumsize do
    Fertig:=Fertig and (Album[I]>0);
  until Fertig;
end;

procedure Statistik;

var  I      : Integer;

begin
  for I:=1 to Laeufe do
  begin
    Simulation;
    if Packcount<Min then Min:=Packcount;
    if Packcount>Max then Max:=Packcount;
    Mittel:=Mittel+1.0*Packcount/Laeufe;
  end;
end;

procedure Ausgabe;

var Uebrig : Integer;

begin
  Uebrig:=Trunc(Mittel*Packsize);
  WriteLn;
  WriteLn('kleinste Zahl an P„ckchen : ',Min:6);
  WriteLn('gr”áte   Zahl an P„ckchen : ',Max:6);
  WriteLn('Mittelwert                : ',Mittel:6:1);
  WriteLn('šberschuss                : ',100*(1-(Albumsize/Uebrig)):6:1,' %');
end;

begin
  ClrScr;
  Max:=-1;
  Min:=MaxInt;
  Eingabe;
  Statistik;
  Ausgabe;
end.
