依然是delphi双色球选号的问题!!!! 本帖最后由 qixiwz 于 2009-08-02 14:57:13 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LZ 很多方法可以解决你的困惑。链表,数组etc.刚开始都有难度的。 LS可以帮到你吧。 好像不难嘛!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; 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; DELPHI 试题 如何在网页中调用动态库? 发送消息的问题!!!! 初学者:if showmodal = mrok then这个里面的一个弹出窗口怎么没显示,这到底是什么机制啊? 简单问题,来吧. 奇怪问题?! 如何让TreeView控件的选定节点的字体颜色变为红色? 在线等待,简单啊.散分 两个rzpanel上下重叠显示的问题 收购成熟的流通企业进销存软件(家电) ascii码库存放在哪里? 使用XpMan控件 DBGrid的PickList中不支持中文输入
刚开始都有难度的。 LS可以帮到你吧。
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;
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;