int a[5]
int len1,len2,len3
void input(int len1,int len2,int len3)
{
printf("%d %d %d\n",a[len1],a[len2],a[len3])
}
void solve(int len1,int len2,int len3)
{
input(len1,len2,len3)
if(len1==2) return
if(len3<4) len3++
else if(len2<3)
{
len2++
len3=len2+1
}
else if(len1<2)
{
len1++
len2=len1+1
len3=len2+1
}
solve(len1,len2,len3)
}
void main()
{
int i
for(i=0i<5i++) a[i]=i+1
printf("所构成组合是:\n")
solve(0,1,2)
return
}
CTestPermutation::~CTestPermutation(){
cout<<">>>>>>>>>>>>>>>>>>>>>>>>CTestPermutation::~CTestPermutation()"<<endl
}
void CTestPermutation::DoTest()
{
cout<<"-------将N个数进行排列组合-------"<<endl<<endl
vector<int>vecNums,vecPermutated
cout<<"示例数据:"
for(int i = 1i <5i++)
{
vecNums.push_back(i)
cout<<i<<" "
}
cout<<endl
cout<<"排列组合结果:"<<endl
Permutation(vecPermutated,vecNums)
}
unit Unit2interface
uses
Classes,ADODB,SysUtils,DB,ActiveX
type
AllNumber = class(TThread)
private
{ Private declarations }
protected
procedure Executeoverride
procedure ADOADDEdit(ado:TADOQuerystr: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: TADOQuerystr: 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.0Data Source=DataBase\data.mdbPersist 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选六就可以了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)