procedure AllList(FullStr: String; ResultStr: String; MaxLength: Integer); var I: Integer; begin if Length(ResultStr) = MaxLength then begin Writeln(ResultStr); Exit; end; for I := 1 to Length(FullStr) do begin if Pos(FullStr[I], ResultStr) = 0 then AllList(FullStr, ResultStr + FullStr[I], MaxLength); end; end; 调用 var I: Integer; S: String; begin S := 'abcdefgh'; for I := 1 to Length(S) do AllList(S, '', I); readln; end.
var
I: Integer;
begin
if Length(ResultStr) = MaxLength then
begin
Writeln(ResultStr);
Exit;
end; for I := 1 to Length(FullStr) do
begin
if Pos(FullStr[I], ResultStr) = 0 then
AllList(FullStr, ResultStr + FullStr[I], MaxLength);
end;
end;
调用
var
I: Integer;
S: String;
begin
S := 'abcdefgh';
for I := 1 to Length(S) do
AllList(S, '', I);
readln;
end.