测试数据都过不了...用样例数据测试时快排里的i和j都停在3和5上出不去了...
帮忙看看,谢谢...........
program rq111;
var nam,num:array [1..5000] of string;
i,j,n,len:longint;
procedure qsort(l,r:longint);
var i,j:longint;
temp,x1,x2:string;
begin
i:=l; j:=r;
x1:=nam[(i+j) div 2];
x2:=num[(i+j) div 2];
repeat
while (num[i]>x2)or((num[i]=x2)and(nam[i]<x1)) do inc(i);
while (num[j]<x2)or((num[j]=x2)and(nam[j]>x1)) do dec(j);
if i<=j then
begin
temp:=nam[i]; nam[i]:=nam[j]; nam[j]:=temp;
temp:=num[i]; num[i]:=num[j]; num[j]:=temp;
inc(j);
dec(i);
end;
until i>j ;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
begin
readln(n); len:=0;
for i:=1 to n do
begin
readln(nam[i]);
readln(num[i]);
while num[i,1]='0' do delete(num[i],1,1);
if len<length(num[i]) then len:=length(num[i]);
end;
for i:=1 to n do
while length(num[i])<len do num[i]:=' '+num[i];
qsort(1,n);
for i:=1 to n do writeln(nam[i]);
readln;
end.
传说中的吐血...
temp:=nam[i]; nam[i]:=nam[j]; nam[j]:=temp;
temp:=num[i]; num[i]:=num[j]; num[j]:=temp;
inc(j);
dec(i);
崩溃啊!!!
测试结果1: 通过本测试点|有效耗时172ms
测试结果2: 通过本测试点|有效耗时156ms
测试结果3: 通过本测试点|有效耗时172ms
测试结果4: 通过本测试点|有效耗时172ms
测试结果5: 通过本测试点|有效耗时219ms
测试结果6: 通过本测试点|有效耗时203ms
测试结果7: 通过本测试点|有效耗时203ms
测试结果8: 通过本测试点|有效耗时218ms
测试结果9: 通过本测试点|有效耗时187ms
测试结果10: 通过本测试点|有效耗时266ms
program rq111;
var nam,num:array [1..5000] of string;
i,j,n,len:longint;
procedure qsort(l,r:longint);
var i,j:longint;
temp,x1,x2:string;
begin
i:=l; j:=r;
x1:=nam[(i+j) div 2];
x2:=num[(i+j) div 2];
repeat
while (num[i]>x2)or((num[i]=x2)and(nam[i]<x1)) do inc(i);
while (num[j]<x2)or((num[j]=x2)and(nam[j]>x1)) do dec(j);
if i<=j then
begin
temp:=nam[i]; nam[i]:=nam[j]; nam[j]:=temp;
temp:=num[i]; num[i]:=num[j]; num[j]:=temp;
inc(i);
dec(j);
end;
until i>j ;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
begin
readln(n); len:=0;
for i:=1 to n do
begin
readln(nam[i]);
readln(num[i]);
while num[i,1]='0' do delete(num[i],1,1);
if len<length(num[i]) then len:=length(num[i]);
end;
for i:=1 to n do
while length(num[i])<len do num[i]:=' '+num[i];
qsort(1,n);
for i:=1 to n do writeln(nam[i]);
readln;
end.