本帖最后由 qixiwz 于 2009-08-02 14:57:13 编辑

解决方案 »

  1.   

    LZ 很多方法可以解决你的困惑。链表,数组etc.
    刚开始都有难度的。 LS可以帮到你吧。
      

  2.   

    好像不难嘛!
    procedure SelectBall(const AStart, AEnd, ASelectCount: Byte; ASelectBalls: TStrings);
    var
      i, j    : Integer;
      FAllBall: TStrings;
    begin
      FAllBall := TStringList.Create;
      try
        ASelectBalls.Clear;
        for i:=AStart to AEnd do
          FAllBall.Add(FormatFloat('00', i));
        for i:=0 to ASelectCount-1 do
        begin
          Randomize;
          j := RandomRange(0, FAllBall.Count-1);
          ASelectBalls.Add(FAllBall[j]);
          FAllBall.Delete(j);
        end;
        TStringList(ASelectBalls).Sort;
      finally
        FreeAndNil(FAllBall);
      end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
      FStrings: TStrings;
    begin
      FStrings := TStringList.Create;
      try
        SelectBall(1, 33, 6, FStrings);
        ShowMessage('红球' + #13#10 + FStrings.Text);
        SelectBall(1, 16, 1, FStrings);
        ShowMessage('蓝球' + #13#10 + FStrings.Text);
      finally
        FreeAndNil(FStrings);
      end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
        i, j, k, MinIndex: Integer;
        Temp, TmpStr: string;
        BallList, MinList: TStringList;
        TmpList: TStringList;
        RandomIndex: Integer;
    begin
        try
            BallList := TStringList.Create;
            RzMemoDis.Clear;
            RzMemoDis.Lines.Add('');
            //一共产生几注
            for k := 1 to CountZhu.IntValue do
            begin
                BallList.Clear;
                for i := 0 to 32 do
                begin
                    BallList.Add(IntToStr(i + 1));
                end;            for i := 0 to 5 do
                begin
                    Randomize;
                    RandomIndex := Random(BallList.Count - 1);
                    case i of
                        0: RedFirst.Text := BallList.Strings[RandomIndex];
                        1: RedSecond.Text := BallList.Strings[RandomIndex];
                        2: RedThird.Text := BallList.Strings[RandomIndex];
                        3: RedFourth.Text := BallList.Strings[RandomIndex];
                        4: RedFifth.Text := BallList.Strings[RandomIndex];
                        5: RedSixth.Text := BallList.Strings[RandomIndex];
                    end;
                    BallList.Delete(RandomIndex);
                end;
                Randomize;
                BlueBall.Text := IntToStr(RandomRange(1, 16));
                Label1.Caption := '';
                MinList := TStringList.Create;
                TmpList := TStringList.Create;
                with MinList do
                begin
                    Add(RedFirst.Text);
                    Add(RedSecond.Text);
                    Add(RedThird.Text);
                    Add(RedFourth.Text);
                    Add(RedFifth.Text);
                    Add(RedSixth.Text);
                    MinIndex := 0;
                    for j := 0 to 4 do
                    begin
                        for i := 1 to MinList.Count - 1 do
                        begin
                            if StrToInt(Strings[MinIndex]) > StrToInt(Strings[i]) then
                                MinIndex := i;
                        end;
                        TmpStr := Strings[MinIndex];
                        if StrToInt(TmpStr) < 10 then
                            TmpStr := '0' + TmpStr;
                        if Label1.Caption = '' then
                            Label1.Caption := TmpStr
                        else
                            Label1.Caption := Label1.Caption + '   ' + TmpStr;
                        TmpList.Add(TmpStr);
                        Delete(MinIndex);
                        MinIndex := 0;
                    end;
                    TmpStr := Strings[MinIndex];
                    if StrToInt(TmpStr) < 10 then
                        TmpStr := '0' + TmpStr;
                    Label1.Caption := Label1.Caption + '   ' + TmpStr;
                    TmpList.Add(TmpStr);
                    TmpStr := BlueBall.Text;
                    if StrToInt(TmpStr) < 10 then
                        TmpStr := '0' + TmpStr;
                    TmpList.Add(TmpStr);
                    if TmpList.Count <> 0 then
                    begin
                        FirstRed := StrToInt(TmpList.Strings[0]);
                        SecondRed := StrToInt(TmpList.Strings[1]);
                        ThirdRed := StrToInt(TmpList.Strings[2]);
                        FourthRed := StrToInt(TmpList.Strings[3]);
                        FifthRed := StrToInt(TmpList.Strings[4]);
                        SixthRed := StrToInt(TmpList.Strings[5]);
                        FirstBlue := StrToInt(TmpList.Strings[6]);
                    end;
                    Label2.Caption := TmpStr;
                    case k of
                        0..9:
                            TmpStr := '00' + IntToStr(k);
                        10..99:
                            TmpStr := '0' + IntToStr(k);
                        100..999:
                            TmpStr := IntToStr(k);
                    end;
                    RzMemoDis.Lines.Add(' 第【' + TmpStr + '】注:' + Label1.Caption + '  --  ' + label2.Caption);
                    RzMemoDis.Lines.Add('--------------------------------------------------');
                end;
            end;
        finally
            BallList.Free;
            MinList.Free;
            TmpList.Free;
        end;end;