{读入字符串长度和字符串,打印该串的所有排列}
{当输入字符串长度大于10时,取前10个字符}
源代码:
{读入字符串长度和字符串,打印该串的所有排列}{当输入字符串长度大于10时,取前10个字符}PROGRAM anagram(input,output);VAR i,length:integer; letter,newword:ARRAY[1..10] OF char; used:ARRAY[1..10] OF boolean;PROCEDURE permute(countdown:integer);VAR j:integer;BEGIN IF countdown=0 THEN BEGIN FOR j:=length DOWNTO 1 DO write(newword[j]); writeln END ELSE BEGIN FOR j:=1 TO length DO BEGIN IF NOT used[j] THEN BEGIN used[j]:=true; newword[countdown]:=letter[j]; permute(countdown-1); used[j]:=false END END ENDEND;BEGIN writeln('Please in -->'); read(length); IF length>10 THEN length:=10; FOR i:=1 TO length DO BEGIN used[i]:=false; read(letter[i]); END; permute(length);END.