- 水王争霸
- 2015-03-01 08:37:18 @
program ss3;
var
n,i,j,m:longint;
a:array[1..1000]of ansistring;
b:array[1..10000]of ansistring;
procedure aa(l,r:longint);
var i,j:longint;
mid,p,mid1:ansistring;
begin
i:=l;j:=r;
mid:=a[(l+r)div 2];
mid1:=b[(l+r) div 2];
repeat
while (length(a[i])>length(mid))or ((length(a[i])=length(mid))and(a[i]>mid))or((a[i]=mid)and (b[i]<mid1))do inc(i);
while (length(a[j])<length(mid))or ((length(a[j])=length(mid))and(a[j]<mid))or((a[j]=mid)and (b[j]>mid1))do dec(j);
if i<=j then
begin
p:=a[i];a[i]:=a[j];a[j]:=p;
p:=b[i];b[i]:=b[j];b[j]:=p;
inc(i);dec(j);
end;
until i>j;
if l<j then aa(l,j);
if i<r then aa(i,r);
end;
begin
readln(n);
for i:=1 to n do
begin
readln(b[i]);
readln(a[i]);
end;
aa(1,n);
for i:=1 to n do
begin
writeln(b[i]);
end;
end.