没忽略空格竟AC
var way:string;
a,b:array[1..100000] of string;
n:longint;
function cl(a,b:string):boolean;
begin
if (way='inc')or(way='dec') then exit(a>b);
exit(lowercase(a)>lowercase(b))
end;
procedure scanf;
var i:longint;
begin
readln(way);
readln(n);
for i:=1 to n do
readln(a[i]);
end;
procedure sort;
var i,j:longint;
tmp:string;
begin
b:=a;
for i:=1 to n-1 do
for j:=i+1 to n do
if cl(b[i],b[j]) then
begin
tmp:=b[i];
b[i]:=b[j];
b[j]:=tmp;
end;
a:=b;
if (way='dec')or(way='ncdec') then
begin
for i:=1 to n do
a[i]:=b[n+1-i];
end;
end;
procedure printf;
var i:longint;
begin
for i:=1 to n do
writeln(a[i]);
end;
begin
scanf;
sort;
printf;
end.