(*//
标题:排列组合
说明:只处理可视字符;使用时可以替换一下
设计:Zswang
日期:2002-04-30
支持:wjhu111@21cn.com
//*)
///////Begin Source
function PermutationCombination(mArr: array of string;
mStrings: TStrings): Boolean;
var
I, J: Integer;
T: string;
S: string;
begin
Result := False;
if not Assigned(mStrings) then Exit;
mStrings.Clear;
T := '';
for I := Low(mArr) to High(mArr) do
if mArr[I] <> '' then begin
T := T + mArr[I][1];
S := S + mArr[I][Length(mArr[I])];
end else Exit;
while T <> S do try
mStrings.Add(T);
J := Length(S);
for I := High(mArr) downto Low(mArr) do begin
if Pos(T[J], mArr[I]) >= Length(mArr[I]) then
T[J] := mArr[I][1]
else begin
T[J] := mArr[I][Pos(T[J], mArr[I]) + 1];
Break;
end;
Dec(J);
end;
mStrings.Add(S);
except
Exit;
end;
Result := True;
end; { PermutationCombination }
///////End Source
///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
PermutationCombination(['ACDE', 'FGH', 'IJKL', 'MNO', 'PQRST'], Memo1.Lines)
end;
///////End Demo