你可以手工构造更大的数,举个例子: a,x:byte;//我这儿为了给你讲清楚,所以取小一点的类型 a,最开始清0,x是你的累加器,当x累加到最大值256时,即 if x=256 then begin x:=0; a:=a+1; end; 这样你是不是就可以把最大值扩展到256*256了,如果再加一个变量,b:byte;存放a的进位,那么 if x=256 then begin x:=0; a:=a+1; if a=256 then begin a:=0; b:=b+1; end; end;这样的话,是不是你的最大值就是256*256*256了,扩展了多少倍?
嗯、谢谢了、这个方法不错、(aa/bb是允许的) 假设存在字符集合['a','b']、最小长度1、最大长度2、那么应该有下面的结果 a b aa ab ba bb(不好意思、我前面举例中忘记里重复的)
上面的排列组合,我给你了一下:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Memo2: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}//该过程是取得某固定长度的字符串排列到list中 procedure aPL(ConstStr:string; Str:String; Len:integer; var list:TStringlist); var i,l:integer; s:string; begin l:=length(ConstStr); for i:=1 to l do begin S:=Str+ConstStr[i]; if Len-1=0 then list.Add(S) else aPL(ConstStr,s,Len-1,list); end; end;//该过程是取得最小长度到最大长度的所有的排列 procedure PL(ConstStr:String; iMin:integer; iMax:integer; var list:TStringlist); var i:integer; begin for i:=iMin to iMax do aPL(ConstStr,'',i,list); end;//测试按钮 procedure TForm1.Button1Click(Sender: TObject); var list:TStringlist; begin list:=TStringlist.Create; PL('ABCD',2,3, list); memo1.Lines.Text:=list.Text; list.Free; end;end.
然后写个函数,生成所有组合
你可以手工构造更大的数,举个例子:
a,x:byte;//我这儿为了给你讲清楚,所以取小一点的类型
a,最开始清0,x是你的累加器,当x累加到最大值256时,即
if x=256 then begin
x:=0;
a:=a+1;
end;
这样你是不是就可以把最大值扩展到256*256了,如果再加一个变量,b:byte;存放a的进位,那么
if x=256 then begin
x:=0;
a:=a+1;
if a=256 then begin
a:=0;
b:=b+1;
end;
end;这样的话,是不是你的最大值就是256*256*256了,扩展了多少倍?
根据上面的原理,你可以设想一下,如果你弄一个动态数组存放进制的话,是不是存放的数就更大了关于你那个排列组合,问一下你是不是不能出现aa,bb,cc的情况
假设存在字符集合['a','b']、最小长度1、最大长度2、那么应该有下面的结果
a
b
aa
ab
ba
bb(不好意思、我前面举例中忘记里重复的)
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}//该过程是取得某固定长度的字符串排列到list中
procedure aPL(ConstStr:string; Str:String; Len:integer; var list:TStringlist);
var
i,l:integer;
s:string;
begin
l:=length(ConstStr);
for i:=1 to l do begin
S:=Str+ConstStr[i];
if Len-1=0 then
list.Add(S)
else
aPL(ConstStr,s,Len-1,list);
end;
end;//该过程是取得最小长度到最大长度的所有的排列
procedure PL(ConstStr:String; iMin:integer; iMax:integer; var list:TStringlist);
var
i:integer;
begin
for i:=iMin to iMax do
aPL(ConstStr,'',i,list);
end;//测试按钮
procedure TForm1.Button1Click(Sender: TObject);
var
list:TStringlist;
begin
list:=TStringlist.Create;
PL('ABCD',2,3, list);
memo1.Lines.Text:=list.Text;
list.Free;
end;end.