如:有3个数 它的排列有6钟
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
现在怎么得到这6种的数组
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
现在怎么得到这6种的数组
解决方案 »
- 求delphi数据库问题"教案与作业管理软件生成设计"
- 关于Cleintdataset的Filter为一个汉字的问题
- 判断文件夹下随时创建的文件,如何得到刚建立的文件的名和路径
- 问个控件简单问题
- QuickReport问题
- 怎么当程序没响应时,程序自已解除
- wise怎么打包ado?
- 我用access做的delphi6.0程序怎样才能在没有安装dephi的机子上运行?直接把运行程序复制过去,建立了odbc连接,运行不了?
- 做安装程序时,客户端需要sql server 2000 的那些 dll 文件,我不想在客户端安装sql server
- 可以给我介绍一些关于CASE工具的东东吗?比如,流行的有那些?你们一般都使用他们吗?
- 新手想学习做一个Edit的组件,主要功能是设一属性CanAccept为真时,Edit则只能输入数字,请问怎样实现!
- 請教一個隨機號碼的函數
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type TMultiArr = array of array of integer;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function GetArr(arr: array of integer;var rs:TMultiArr):boolean;
function GetFactorial(num:integer):Longword;
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }function TForm1.GetArr(arr: array of integer;
var rs:TMultiArr): boolean;
var
i,j,k:integer;
tmpArr:array of integer;
begin
Result := True;
SetLength(tmpArr,High(arr)-Low(arr));
for i:= Low(arr) to High(arr) do
begin
k:=0;
for j := Low(arr) to High(arr) do
begin
if i<>j then
begin
tmpArr[k] := arr[j];
Inc(k);
end;
end;
if (High(tmpArr)-Low(tmpArr)=0) then
begin
SetLength(rs,High(rs)-Low(rs)+2);
end;
if (High(tmpArr)-Low(tmpArr)>-1) then
begin
Memo1.Lines.Add(IntToStr(tmpArr[Low(tmpArr)]) + ':' + IntToStr(tmpArr[High(tmpArr)]));
GetArr(tmpArr,rs);
k := High(rs)-Low(rs);
for j := GetFactorial(High(tmpArr)-Low(tmpArr)+1) downto 1 do
begin
SetLength(rs[k],High(rs[k])-Low(rs[k])+2);
rs[k,High(rs[k])-Low(rs[k])] := arr[i];
dec(k);
end;
end;
end;
if High(arr)-Low(arr)=0 then
begin
SetLength(rs[High(rs)-Low(rs)],High(rs[High(rs)-Low(rs)])-Low(rs[High(rs)-Low(rs)])+2);
rs[High(rs)-Low(rs),High(rs[High(rs)-Low(rs)])-Low(rs[High(rs)-Low(rs)])] := arr[High(arr)];
end;
Result := True;
end;procedure TForm1.Button1Click(Sender: TObject);
var
a,b: TMultiArr;
c:array of integer;
begin
SetLength(a,2);
SetLength(a[0],2);
SetLength(a[1],2);
a[0,0]:=1;
a[0,1]:=2;
a[1,0]:=3;
a[1,1]:=4;
b := a;
showmessage(IntToStr(b[0,1]));
showmessage(IntToStr(High(c)-Low(c)));
end;procedure TForm1.Button2Click(Sender: TObject);
var
rs:TMultiArr;
begin
GetArr([1,2,3,4,5],rs);
showmessage(IntToStr(High(rs)-Low(rs)+1));
end;function TForm1.GetFactorial(num:integer): Longword;
begin
if num < 0 then
begin
Result := 0;
Exit;
end;
if num<=1 then
begin
Result := 1;
Exit;
end;
Result := num * GetFactorial(num-1);
end;procedure TForm1.Button3Click(Sender: TObject);
begin
showmessage(IntToStr(GetFactorial(5)));
end;end.
好象不对哦
SysUtils;type TChSet=set of 'A'..'Z';function Arranege(Cn, Cm: byte): integer;
procedure GenData(m, n: byte; t:string; s:TchSet);
var c:char;
begin
if Length(t)=n then begin write(t:n+2); Result:=Result+1; end
else for c:='A' to Chr(64+m) do
if not (c in s) then GenData(m, n, t+c, s+[c]);
end;
begin
Result:=0;
GenData(Cn, Cm, '', []);
end;function Combine(Pn, Pm: byte): integer;
procedure GenData(m, n: byte; t:string; s:TchSet);
var c, c1:char;
begin
if Length(t)=n then begin write(t:n+2); Result:=Result+1; end else
begin
if Length(t)=0 then c1:='A' else c1:=Succ(t[Length(t)]);
for c:=c1 to Chr(64+m) do
if not (c in s) then GenData(m, n, t+c, s+[c]);
end;
end;
begin
Result:=0;
GenData(Pn, Pm, '', []);
end;begin
{ TODO -oUser -cConsole Main : Insert code here }
writeln('Arrange:');
writeln(' Total=', Arranege(5, 3));
writeln('Combine:');
writeln(' Total=', Combine(5, 3));
readln;
end.绝对可用的
http://lysoft.7u7.net
ly_liuyang(Liu Yang) 他做的可以 了
function Collocate(mStrings: TStrings; mStr: string): Boolean; { 全排列 }
procedure pCollocate(mLeft, mRight: string);
var
I, L: Integer;
Temp: string;
begin
L := Length(mLeft);
if L = 0 then
mStrings.Add(mRight)
else for I := 1 to L do begin
Temp := mLeft;
Delete(Temp, I, 1);
pCollocate(Temp, Concat(mRight, mLeft[I]));
end;
end;
begin
Result := False;
if not Assigned(mStrings) then Exit;
mStrings.BeginUpdate;
try
mStrings.Clear;
pCollocate(mStr, '');
finally
mStrings.EndUpdate;
end;
Result := True;
end; { Collocate }procedure TForm1.Button1Click(Sender: TObject);
begin
Collocate(Memo1.Lines, '12345')
end;
你的程序有个问题,就是如果要排列的数都不重复,比如1234,那么得出来的结果24组没错 但是如果是1123,那么你的程序的出来的结果就会出现重复。
如果是1111,应该来说只有1组,但是你的程序得出24组1111。