排列组合算法程序用C.C++.asp.或者jsp.vb.随便一种语言.输出1到33.33个数.从中选6个数.不重复.输出

问题描述:

排列组合算法程序
用C.C++.asp.或者jsp.vb.随便一种语言.输出
1到33.33个数.从中选6个数.不重复.输出所有可能排列.不分顺序.
写出完成算法程序.附带注释.
1个回答 分类:综合 2014-11-14

问题解答:

我来补答
unit Unit2;
interface
uses
Classes,ADODB,SysUtils,DB,ActiveX ;
type
AllNumber = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
procedure 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,
procedure AllNumber.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ AllNumber }
procedure AllNumber.ADOADDEdit(ado: TADOQuery; str: String);
begin
ado.Close ;
ado.SQL.Clear ;
ado.SQL.Add(str) ;
ado.ExecSQL ;
end;
procedure 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 (ae) and (af) and (ag) and (bc) and (bd) and (be) and (bf) and (bg) and (cd) and (ce) and (cf) and (cg) and (de) and (df) and (dg) and (ef) and (eg) and (fg) 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选六就可以了
 
 
展开全文阅读
剩余:2000
上一页:算数过程
下一页:enjoy的反义词
也许感兴趣的知识