linlin @ 2017-05-04 21:32:21
var n,y,s,g,z:array[1..301] of integer;
i,j,t,a:longint;
begin
read(a);
for i:=1 to a do
readln(y[i],s[i],g[i]);
for i:=1 to a do
n[i]:=i;
for i:=1 to a do
z[i]:=y[i]+s[i]+g[i];
for i:=1 to a-1 do
for j:=i+1 to a do
begin
if z[j]>z[i] then begin
t:=n[i];n[i]:=n[j];n[j]:=t;
t:=y[i];y[i]:=y[j];y[j]:=t;
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=g[i];g[i]:=g[j];g[j]:=t;
t:=z[i];z[i]:=z[j];z[j]:=t;
end
else if( z[j]=z[i])and((j>i)or(j<i)) then begin
t:=n[i];n[i]:=n[j];n[j]:=t;
t:=y[i];y[i]:=y[j];y[j]:=t;
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=g[i];g[i]:=g[j];g[j]:=t;
t:=z[i];z[i]:=z[j];z[j]:=t;
end;
end;
for i:=1 to 5 do
writeln(n[i],' ',z[i]);
end.
by I_promise @ 2017-05-13 14:47:14
排序方法改一下
by szfcpp @ 2017-05-13 19:15:35
by 蒟蒻lxy @ 2017-05-14 12:05:21
by 蒟蒻lxy @ 2017-05-14 12:06:00
by 蒟蒻lxy @ 2017-05-14 12:07:24
by yqh123 @ 2017-07-18 17:03:52
var i,j,n:longint; zf,yw,yy,sx,id:array[0..100000] of longint;
procedure swap(var a,b:longint);
var t:longint;
begin
t:=a;
a:=b;
b:=t;
end;
procedure qsort(l,r:longint);
var mid,mid1,mid2:longint;
begin
i:=l;
j:=r;
mid:=zf[(i+j) div 2];
mid1:=yw[(i+j) div 2];
mid2:=id[(i+j) div 2];
while i<j do
begin
while (zf[i]>mid) or
(zf[i]=mid) and (yw[i]>mid1) or
(zf[i]=mid) and (yw[i]=mid1) and (id[i]<mid2) do inc(i);
while (zf[j]<mid) or
(zf[j]=mid) and (yw[j]<mid1) or
(zf[j]=mid) and (yw[j]=mid1) and (id[j]>mid2) do dec(j);
if i<=j then
begin
swap(zf[i],zf[j]);
swap(yw[i],yw[j]);
swap(id[i],id[j]);
swap(yy[i],yy[j]);
inc(i); dec(j);
end;
end;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
begin
readln(n);
for i:=1 to n do
begin
readln(yw[i],sx[i],yy[i]);
zf[i]:=yw[i]+sx[i]+yy[i];
id[i]:=i;
end;
qsort(1,n);
for i:=1 to 5 do
writeln(id[i],' ',zf[i]);
end.
可以参考一下