排列组合算法程序

发布网友 发布时间:2022-04-23 02:30

我来回答

1个回答

热心网友 时间:2022-05-19 07:58

unit Unit2;

interface

uses
Classes,ADODB,SysUtils,DB,ActiveX ;

type
AllNumber = class(TThread)
private
{ Private declarations }
protected
procere Execute; override;
procere ADOADDEdit(ado:TADOQuery;str:String);
end;

implementation

{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,

Synchronize(UpdateCaption);

and UpdateCaption could look like,

procere AllNumber.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }

{ AllNumber }

procere AllNumber.ADOADDEdit(ado: TADOQuery; str: String);
begin
ado.Close ;
ado.SQL.Clear ;
ado.SQL.Add(str) ;
ado.ExecSQL ;
end;

procere AllNumber.Execute;
var
ado:TADOQuery;
a,b,c,d,e,f,g,sum:Integer;
str:string;
begin
CoInitialize(nil);
ado := TADOQuery.Create(nil);
ado.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataBase\data.mdb;Persist Security Info=False';
FreeOnTerminate := true;
for a := 1 to 30 do
for b:= a+1 to 31 do
for c := b+1 to 32 do
for d := c+1 to 33 do
for e := d+1 to 34 do
for f := e+1 to 35 do
for g := f+1 to 36 do
begin
if (a <> b) and (a <>c) and (a<> d) and (a<>e) and (a<>f) and (a<>g) and (b<>c) and (b<>d) and (b<>e) and (b<>f) and (b<>g) and (c<>d) and (c<>e) and (c<>f) and (c<>g) and (d<>e) and (d<>f) and (d<>g) and (e<>f) and (e<>g) and (f<>g) then
begin
sum := a+b+c+d+e+f+g;
str := 'insert into numnumshu (one,two,three,four,five,six,seven,NumSum) Values('''+IntToStr(a)+''','''+IntToStr(b)+''','''+IntToStr(c)+''','''+IntToStr(d)+''','''+IntToStr(e)+''','''+IntToStr(f)+''','''+IntToStr(g)+''','''+IntToStr(sum)+''')';
ADOADDEdit(ado,str);
end;
end;
FreeAndNil(ado);
CoUninitialize();
end;

end.

这个是我自己写的一个线程,用来产生所有不同的号码,不过我算得是36选七,你把它改成33选六就可以了

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com