讨论 / 诸位大牛帮忙看看怎么会死循环啊......
!@#$% 2010-09-19 19:45:00
点我顶贴 收藏 删除
晕死...如此水题,居然会死循环,好像是栈溢出...

测试数据都过不了...用样例数据测试时快排里的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.

#1 !@#$%@2010-09-19 16:07:00
回复 删除
靠!!!!!

传说中的吐血...

temp:=nam[i]; nam[i]:=nam[j]; nam[j]:=temp;

temp:=num[i]; num[i]:=num[j]; num[j]:=temp;

inc(j);

dec(i);

崩溃啊!!!

#2 !@#$%@2010-09-19 16:09:00
回复 删除
终于AC了...

测试结果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.

#3 lxl@2010-09-19 19:45:00
回复 删除
无语。。

。。。。。。

查看更多回复
提交回复