求助:從編號為0到9的十個球中任選5球且滿足選出的任意一組球的編號至多有兩個和其它組球的編號相同的組合。 

解决方案 »

  1.   

    function ran(AStart, AEnd, ACount: Integer): string;
    var
      I, X, A: Integer;
      AList: TList;
    begin
      AList := TList.Create;
      randomize;
      for I := AStart to AEnd do
        AList.Add(Pointer(I));
      for I := 1 to ACount do
      begin
        X := Random(AList.Count);
        A := Integer(AList[X]);
        AList.delete(X);
        Result := Result + ',' + InttoStr(A);
      end;
      Result := copy(Result, 2, Length(Result));
      AList.Free;
    end;
      

  2.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
     i,ii,iii: integer;
     str: string;
    begin
       ii:=0;
       randomize;
    for iii:=1 to 3 do
     Begin
       repeat
          ii:=ii+1;
          i:=random(9);
            if ((i)>=0) and ((i)<=9) then
              str:=str+' '+inttostr(i);
       until  ii>5;
       form1.Canvas.TextOut(10,10*iii,str);   str:='';
       ii:=0;
     end;
    end;
      

  3.   

    我刚好以前写了一个
    http://blog.csdn.net/confucius/archive/2006/12/25/1460050.aspx