真是不甘!以下是我的程序
你不妨试一下,在from上放一个button, Tlistbox, Tlabel, Tedit;
你要排列的字符串就放在edit1里面
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
ListBox1: TListBox;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function insertanypos(str1, str2: string): Tstrings;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
i,x: integer;
tmpstrs,mainstrs: Tstrings;
begin
i := 2;
tmpstrs := Tstringlist.Create;
mainstrs := insertanypos(edit1.text[2], edit1.text[1]);
while i <= length(edit1.text) do
begin
tmpstrs.Clear;
tmpstrs.addstrings(mainstrs);
mainstrs.clear;
inc(i);
for x := 0 to tmpstrs.count - 1 do
begin
mainstrs.addstrings( insertanypos(edit1.text, tmpstrs[x]));
end;
end;
listbox1.items := tmpstrs;
label1.Caption := inttostr(tmpstrs.count);
tmpstrs.Free;
end;
function Tform1.insertanypos(str1, str2: string): Tstrings;
var
i: integer;
tmpstr: string;
begin
result := Tstringlist.create;
result.add(str2+str1);
for i := 0 to length(str2) - 1 do
begin
tmpstr := copy(str2, 1, i) + str1 + copy(str2, i + 1, length(str2) - i);
result.add(tmpstr);
end;
end;
end.