- 笨笨的单词排序
- 2009-01-29 13:34:26 @
var n,flag,i,j,k:longint;
c:char;
s,temp1,temp2:string;
word:array[0..100] of string;
shun:array['a'..'z'] of longint;
begin
read(s,n);
for i:=1 to n do
begin
readln;
while not(eoln) do
begin
read(c) ;
word[i]:=word[i]+c;
end;
end;
read(flag);
if flag=1 then for i:=1 to 26 do shun[s[i]]:=i
else for i:=1 to 26 do shun[s[i]]:=27-i;
for i:=1 to n-1 do
for j:=1 to n-i do
begin
temp1:=word[j];temp2:=word[j+1];
k:=1;
while temp1[k]=temp2[k] do inc(k);
if shun[temp1[k]]>shun[temp2[k]]
then begin word[0]:=word[j];word[j]:=word[j+1];word[j+1]:=word[0];end;
end;
for i:=1 to n-1 do writeln(word[i]);
write(word[n]);
end.
0 条评论
目前还没有评论...