- 笨笨的单词排序
- 2009-11-01 21:31:14 @
program p1550;
type str1=record
str:string;
end;
var ch:char;
a:array[1..26] of integer;
b:array[1..1000] of str1;
i,n,k,j:longint;
procedure sort(m:longint);
var i,j:longint;
tmp:char;
begin
for i:=1 to length(b[m].str)-1 do
for j:=i+1 to length(b[m].str) do
if a[ord(b[m].str[i])-96]>a[ord(b[m].str[j])-96]
then begin tmp:=b[m].str[i];
b[m].str[i]:=b[m].str[j];
b[m].str[j]:=tmp;
end;
end;
begin
for i:=1 to 26 do
begin
read(ch);
a[ord(ch)-96]:=i;
end;
readln;
readln(n);
for i:=1 to n do
readln(b[i].str);
readln(k);
for i:=1 to n do
begin
sort(i);
if k=1 then writeln(b[i].str)
else if k=0 then begin
for j:=length(b[i].str) downto 1 do
write(b[i].str[j]);
writeln;
end;
end;
for i:=1 to 26 do write(a[i]:3);
end.