#6178: 菜鸟求解


jkljk6 (钱猪肉)

學校 : 上海市娄山中学
編號 : 18746
來源 : [180.158.73.157]
最後登入時間 :
2016-06-27 22:40:08
d550. 物件排序 | From: [180.158.88.219] | 發表日期 : 2011-12-18 09:22

var i,j,k,l,a,b,c,max:longint;
x:array[1..10000,1..200]of longint;

procedure qsort(l,r:longint);
var i,j,mid,y,t,l1:longint;
begin
i:=l;j:=r;mid:=(l+r) div 2;

repeat

repeat
t:=0;
for l1:=1 to k do begin
if x[i,l1]<x[mid,l1] then t:=1
else if x[i,l1]>x[mid,l1] then t:=2;
if t<>0 then break;
end;
if t=1 then inc(i);
until t<>1;

repeat
t:=0;
for l1:=1 to k do begin
if x[mid,l1]<x[j,l1] then t:=1
else if x[mid,l1]>x[j,l1] then t:=2;
if t<>0 then break;
end;
if t=1 then dec(j);
until t<>1;

if i<=j then begin
for l1:=1 to k do begin
y:=x[i,l1];x[i,l1]:=x[j,l1];x[j,l1]:=y;
end;
inc(i);dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;

begin
while not eof do begin
readln(a,k);
for i:=1 to a do
for j:=1 to k do read(x[i,j]);
qsort(1,a);
for i:=1 to a do begin
for j:=1 to k do write(x[i,j],' ');
writeln;
end;
end;
end.

20分。。果断求助

 
ZeroJudge Forum