# 158 条题解

• @ 2018-02-03 14:43:42
``````#include<bits/stdc++.h>
using namespace std;
struct student
{
int num;//学号
int chinese;//语文成绩
int math;//数学成绩
int english;//英语成绩
int all;//总分
};
struct student a[1000+10],num,chinese,math,english,all;
int main()
{
int n,i,j;
cin>>n;//输入学生数
for(i=1;i<=n;i++)
{
cin>>a[i].chinese>>a[i].math>>a[i].english;//读取成绩
a[i].all=a[i].chinese+a[i].math+a[i].english;//将总分算出来
a[i].num=i;
}
for(i=1;i<=n;i++)
for(j=1;j<=n-1;j++)
if(a[j].all<a[j+1].all)//如果前者总分小于后者总分
swap(a[j],a[j+1]);//交换这俩的位置
else
if(a[j].all==a[j+1].all && a[j].chinese<a[j+1].chinese)//如果总分相等并且前者语文成绩小于后者语文成绩
swap(a[j],a[j+1]);//交换这俩的位置
for(i=1;i<=5;i++)//输出前五名
cout<<a[i].num<<" "<<a[i].all<<endl;
return 0;
}
``````

``` /*测试结果： #1 Accepted 4ms 376.0 KiB #2 Accepted 3ms 384.0 KiB #3 Accepted 3ms 340.0 KiB #4 Accepted 3ms 384.0 KiB #5 Accepted 3ms 352.0 KiB #6 Accepted 3ms 204.0 KiB #7 Accepted 4ms 356.0 KiB #8 Accepted 4ms 348.0 KiB #9 Accepted 4ms 380.0 KiB #10 Accepted 3ms 340.0 KiB */ ```

• @ 2018-09-19 14:34:53
``````
#include<iostream>
#include<algorithm>
using namespace std;
struct hehe{
int a,b,c,num,sum;
}a[301];
bool cmp(hehe x,hehe y)
{
if(x.sum==y.sum)
{
if(x.a==y.a)
{
return x.num<y.num;
}
return x.a>y.a;
}
return x.sum>y.sum;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].a>>a[i].b>>a[i].c;
a[i].sum=a[i].a+a[i].b+a[i].c;
a[i].num=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++)
{
cout<<a[i].num<<' '<<a[i].sum<<endl;
}
return 0;
}

``````

简单的结构体排序~

• @ 2018-08-08 14:43:47

我又回来了！
var a,b,c:array[1..300] of integer;
i,j,n,x,y:integer;
procedure swap(x,y:integer);
var temp:integer;
begin
temp:=a[x];a[x]:=a[y];a[y]:=temp;
temp:=b[x];b[x]:=b[y];b[y]:=temp;
temp:=c[x];c[x]:=c[y];c[y]:=temp;
end;
procedure qsort(h,l:integer);
var i,j,m:integer;
begin
i:=h;j:=l;m:=c[(i+j) div 2];
repeat
while c[i]>m do inc(i);
while c[j]<m do dec(j);
if i<=j then
begin
swap(i,j);inc(i);dec(j);
end;
until i>j;
if i<l then qsort(i,l);
if j>h then qsort(h,j);
end;
begin
for i:=1 to n do
begin
c[i]:=b[i]+x+y;
end;
qsort(1,n);
for i:=1 to 5 do
for j:=i+1 to n do
if (c[i]=c[j]) and (b[i]<b[j]) then swap(i,j);
for i:=1 to 5 do
for j:=i+1 to n do
if (c[i]=c[j]) and (b[i]=b[j]) and (a[i]>a[j]) then swap(i,j);
for i:=1 to 5 do
writeln(a[i],' ',c[i]);
end.

• @ 2021-08-29 17:05:17
``````#include <bits/stdc++.h>
using namespace std;

int main(){
long long i,ans[20000],x,y,z,n;
cin>>n;
for (i=1;i<=n;i++){
cin>>x>>y>>z;
ans[i]=(x+y+z)*100000000+x*100000+99999-i;
}
sort(ans+1,ans+n+1);
for (i=n;i>n-5;i--)
cout<<99999-ans[i]%100000<<" "<<ans[i]/100000000<<endl;
return 0;
}
``````
• @ 2018-02-03 10:09:22

#include <bits/stdc++.h>
using namespace std;
struct{
int y;
int s;
int e;
int x;
int all;
}a[310],t;
int main(){
int i,j,n;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i].y>>a[i].s>>a[i].e;
for(i=1;i<=n;i++){
a[i].x=i;
a[i].all=a[i].y+a[i].s+a[i].e;
}
for(j=1;j<n;j++){
for(i=1;i<n;i++){
if(a[i].all<a[i+1].all){
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
if(a[i].all==a[i+1].all){
if(a[i].y<a[i+1].y){
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
if(a[i].y==a[i+1].y){
if(a[i].x>a[i+1].x){
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}

}
}
for(i=1;i<=5;i++)
cout<<a[i].x<<" "<<a[i].all<<endl;
return 0;
}

• @ 2018-12-05 16:47:46

#include <stdio.h>
struct chengji
{
int xuehao;
int yuwen ;
int shuxue;
int yingyu;
int sum;
};
int main (void)
{
int a,i,k;
scanf ("%d",&a);
struct chengji didi[a];
for (i=0;i<a;i++)
{
scanf ("%d %d %d",&didi[i].yuwen,&didi[i].shuxue,&didi[i].yingyu);
didi[i].sum=didi[i].yuwen+didi[i].shuxue+didi[i].yingyu;
didi[i].xuehao=i+1;
}
paixu (didi,a);
for (k=0;k<5;k++)
{
printf("%d %d",didi[k].xuehao,didi[k].sum);
printf ("\n");
}
}
void paixu (struct chengji h[],int n)
{
struct chengji temp;
int i,k;
for (i=0;i<n-1;i++)
for (k=0;k<n-1-i;k++)
{
if (h[k].sum<h[k+1].sum)
{
temp=h[k];
h[k]=h[k+1];
h[k+1]=temp;
}
if (h[k].sum==h[k+1].sum)
{
if (h[k].yuwen<h[k+1].yuwen)
{
temp=h[k];
h[k]=h[k+1];
h[k+1]=temp;
}
if (h[k].yuwen==h[k+1].yuwen)
{
if (h[k].xuehao>h[k+1].xuehao)
{
temp=h[k];
h[k]=h[k+1];
h[k+1]=temp;
}
}
}
}

}

• @ 2018-01-31 14:07:58

事实上就是一个结构体加上一些嵌套
新人发题解，有异议勿喷（已AC）
#include<bits/stdc++.h>
using namespace std;
int main(){
struct{
int num;
int ch;
int ma;
int en;
int s;
}a[310],t;
int i,n,j;
cin>>n;
for(i=1;i<=n;i++)
a[i].s=0;
for(i=1;i<=n;i++){
cin>>a[i].ch>>a[i].ma>>a[i].en;
a[i].s=a[i].s+a[i].ch+a[i].ma+a[i].en;
a[i].num=i;
}
for(j=1;j<=n-1;j++)
for(i=1;i<=n-1;i++){
if(a[i].s<a[i+1].s){
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
if(a[i].s==a[i+1].s){
if(a[i].ch<a[i+1].ch){
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
if(a[i].ch==a[i+1].ch)
if(a[i].num>a[i+1].num){
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
for(i=1;i<=5;i++)

cout<<a[i].num<<" "<<a[i].s<<endl;
return 0;
}

• @ 2016-11-17 05:16:05
``````#include <iostream>
#include <cmath>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <climits>
#include <algorithm>
using namespace std;

struct stu
{
int num;
int chinese;
int math;
int english;
int sum;
};

bool uu(const stu &x, const stu &y)
{
if(x.sum != y.sum)
return x.sum>y.sum;
else if(x.chinese != y.chinese)
return x.chinese>y.chinese;
else return x.num<y.num;
}

int main()
{
stu a[301];

int n;
cin>>n;

for(int i=1; i<=n; i++)
{
a[i].num=i;
cin>>a[i].chinese>>a[i].math>>a[i].english;
a[i].sum=a[i].chinese+a[i].math+a[i].english;
}

sort(a+1,a+1+n,uu);

for(int i=1;i<=5;i++)
{
cout<<a[i].num<<' '<<a[i].sum<<endl;
}

return 0;
}
``````
• @ 2016-08-27 23:30:17
``````#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

struct student//学生信息
{
int cord;
int ch;
int ma;
int en;
void cls()
{
cord = 0;
ch = 0;
ma = 0;
en = 0;
return;
}
}cla[301];

void swap(int l,int r)//交换
{
struct student temp;
temp.cls();

temp.cord=cla[l].cord;
temp.ch=cla[l].ch;
temp.ma=cla[l].ma;
temp.en=cla[l].en;

cla[l].cord=cla[r].cord;
cla[l].ch=cla[r].ch;
cla[l].ma=cla[r].ma;
cla[l].en=cla[r].en;

cla[r].cord=temp.cord;
cla[r].ch=temp.ch;
cla[r].ma=temp.ma;
cla[r].en=temp.en;
}

void ksort(int l,int r)//快排总分
{
int i=l,j=r;
do
{
if(i<=j)
{
swap(i,j);
++i;
--j;
}
}while(i<=j);
if(l<j)ksort(l,j);
if(i<r)ksort(i,r);
return;
}

void ksort2(int l,int r)//快排语文
{
int mid=cla[(l+r)/2].ch;
int i=l,j=r;
do
{
while(cla[i].ch>mid)++i;
while(cla[j].ch<mid)--j;
if(i<=j)
{
swap(i,j);
++i;
--j;
}
}while(i<=j);
if(l<j)ksort2(l,j);
if(i<r)ksort2(i,r);
return;
}

void ksort3(int l,int r)//快排学号
{
int mid=cla[(l+r)/2].cord;
int i=l,j=r;
do
{
while(cla[i].cord<mid)++i;
while(cla[j].cord>mid)--j;
if(i<=j)
{
swap(i,j);
++i;
--j;
}
}while(i<=j);
if(l<j)ksort3(l,j);
if(i<r)ksort3(i,r);
return;
}

void print(int i)//输出第i个学生信息
{
}

int main()
{
int n;
int i;
for( i = 0 ; i < 301 ; ++i )//结构体初始化
cla[i].cls();
cin >> n;
for( i = 1 ; i <= n; ++i )//输入
{
cla[i].cord = i;
cin >> cla[i].ch >> cla[i].ma >> cla[i].en;
cla[i].add = cla[i].ch + cla[i].ma + cla[i].en;
}
ksort(1,n);//总分排序
int l1;
//***语文排序
for(i=1;i<5;++i)//从i~l1的总分相同，1~5有不确定的 i~l1
{
l1=i;
ksort2(l1,i);
}
//***
//***学号排序
for(i=1;i<5;++i)//从i~l1的语文相同，1~5有不确定的 i~l1
{
l1=i;
while(cla[i].ch==cla[i+1].ch)++i;
ksort3(l1,i);
}
//***
for(i=1;i<=5;++i)//输出
print(i);
return 0;
}
``````
• @ 2017-10-22 16:03:22

for(i=1;i<5;++i)//从i~l1的总分相同，1~5有不确定的 i~l1
{
l1=i;
ksort2(l1,i);
}

您好，请问这一段中1~5起什么作用？为什么是1~5？

• @ 2014-07-06 16:53:02

#include <stdio.h>
struct student
{
int num;
int chinese;
int maths;
int english;
int score;
}student[310];
int main()
{
int i,n,j;
scanf ("%d",&n);
for (i=1;i<=n;i++) student[i].num=i;
for (i=1;i<=n;i++)
{
scanf ("%d %d %d",&student[i].chinese,&student[i].maths,&student[i].english);
student[i].score=student[i].chinese+student[i].maths+student[i].english;
}

for (i=1;i<=n-1;i++)
for (j=1;j<=n-i;j++)
{
if (student[j].score<student[j+1].score)
{
student[0]=student[j];
student[j]=student[j+1];
student[j+1]=student[0];
}
else if (student[j].score==student[j+1].score)
if (student[j].chinese<student[j+1].chinese)
{
student[0]=student[j];
student[j]=student[j+1];
student[j+1]=student[0];
}
}

for (i=1;i<=5;i++)
printf ("%d %d\n",student[i].num,student[i].score);
return 0;
}

• @ 2014-01-01 12:01:38

Vijos 题解：http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
有疑问请留言 共同进步

• @ 2013-12-28 20:22:17

var a,b,c:array[1..300] of integer;
i,j,n,x,y:integer;
procedure swap(x,y:integer);
var temp:integer;
begin
temp:=a[x];a[x]:=a[y];a[y]:=temp;
temp:=b[x];b[x]:=b[y];b[y]:=temp;
temp:=c[x];c[x]:=c[y];c[y]:=temp;
end;
procedure qsort(h,l:integer);
var i,j,m:integer;
begin
i:=h;j:=l;m:=c[(i+j) div 2];
repeat
while c[i]>m do inc(i);
while c[j]<m do dec(j);
if i<=j then
begin
swap(i,j);inc(i);dec(j);
end;
until i>j;
if i<l then qsort(i,l);
if j>h then qsort(h,j);
end;
begin
for i:=1 to n do
begin
c[i]:=b[i]+x+y;
end;
qsort(1,n);
for i:=1 to 5 do
for j:=i+1 to n do
if (c[i]=c[j]) and (b[i]<b[j]) then swap(i,j);
for i:=1 to 5 do
for j:=i+1 to n do
if (c[i]=c[j]) and (b[i]=b[j]) and (a[i]>a[j]) then swap(i,j);
for i:=1 to 5 do
writeln(a[i],' ',c[i]);
end.

• @ 2013-11-30 12:10:34

无敌的sort秒杀
编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 444 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 456 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 452 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 452 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 448 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 452 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 452 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 452 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 452 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 452 KiB, score = 10
Accepted, time = 0 ms, mem = 456 KiB, score = 100

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
typedef struct stu{
int a;
int b;
int c;
int sum;
int num;
}stu;
stu per[301];
int cmp(stu a,stu b){
if(a.sum-b.sum) return a.sum>b.sum;
if(a.a-b.a) return a.a>b.a;
return a.num<b.num;
}
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d %d %d",&per[i].a,&per[i].b,&per[i].c);
per[i].sum=per[i].a+per[i].b+per[i].c;
per[i].num=i;
}
sort(per+1,per+n+1,cmp);
for(int i=1;i<=5;i++) printf("%d %d\n",per[i].num,per[i].sum);
return 0;

}

• @ 2013-11-09 11:55:58

编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 736 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 736 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #4: Accepted, time = 11 ms, mem = 740 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 736 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 740 KiB, score = 10
Accepted, time = 11 ms, mem = 740 KiB, score = 100

### 代码

var
i,j,n,x,y:integer;
a,b,c:array[1..300]of integer;
procedure jk(var m,mm:integer);
var temp:integer;
begin
temp:=m; m:=mm; mm:=temp;
end;
begin
for i:=1 to n do
begin
a[i]:=i;
b[i]:=c[i]+x+y;
end;
for i:=1 to 5 do
for j:=i+1 to n do
if (b[i]<b[j])or((b[i]=b[j])and(c[i]<c[j]))or((b[i]=b[j])and(c[i]=c[j])and(a[i]>a[j])) then
begin
jk(a[i],a[j]);
jk(b[i],b[j]);
jk(c[i],c[j]);
end;
for i:=1 to 5 do
writeln(a[i],' ',b[i]);
end.

• @ 2013-11-06 20:09:01

program p1398；
var i,j,n,x,y,z,t:integer;
a:array[1..300] of record
all,chi,num:longint;
end;

begin
for i:=1 to n do
begin
a[i].all:=x+y+z;
a[i].chi:=x;
a[i].num:=i;
end;
for i:=1 to n do
for j:=1 to n do
begin
if a[i].all>a[j].all then
begin
t:=a[i].all;a[i].all:=a[j].all;a[j].all:=t;
t:=a[i].chi;a[i].chi:=a[j].chi;a[j].chi:=t;
t:=a[i].num;a[i].num:=a[j].num;a[j].num:=t;
end;
if a[i].all=a[j].all then
if a[i].chi>a[j].chi then
begin
t:=a[i].all;a[i].all:=a[j].all;a[j].all:=t;
t:=a[i].chi;a[i].chi:=a[j].chi;a[j].chi:=t;
t:=a[i].num;a[i].num:=a[j].num;a[j].num:=t;
end;
end;
for i:=1 to 5 do writeln(a[i].num,' ',a[i].all);
end.

• @ 2013-10-26 22:17:08

#include <cstdio>
#include <algorithm>
using namespace std;

struct stu
{
int num,gra,ch;
} s[320];

int cpr(stu a,stu b)
{
if(a.gra==b.gra){
if(a.ch==b.ch)
return a.num<b.num;
return a.ch>b.ch;
}
return a.gra>b.gra;
}
int main()
{
// freopen("file.in","r",stdin);
int i,n;
scanf("%d",&n);
for(i=0;i<n;i++){
int ch,ma,en;
scanf("%d%d%d",&s[i].ch,&ma,&en);
s[i].num=i+1;
s[i].gra=s[i].ch+ma+en;
}
sort(s,s+n,cpr);
for(i=0;i<5;i++)
printf("%d %d\n",s[i].num,s[i].gra);
return 0;
}

• @ 2013-10-15 21:49:33

var a:array[0..100,0..1000] of longint;
x,y,z,i,j,m,n,s,l,p:longint;
begin
for i:=1 to n do
begin
a[i,5]:=0;
for j:=1 to 3 do
begin
a[i,5]:=a[i,5]+a[i,j];
end;
a[i,4]:=i;
end;
for i:=1 to n-1 do
for j:=n-1 downto i do
if a[j,5]<a[j+1,5] then
begin
z:=a[j,5];
a[j,5]:=a[j+1,5];
a[j+1,5]:=z;
y:=a[j,1];
a[j,1]:=a[j+1,1];
a[j+1,1]:=y;
x:=a[j,4];
a[j,4]:=a[j+1,4];
a[j+1,4]:=x;
end;
for i:=1 to 5 do
begin
if a[i,5]=a[i+1,5] then
begin
if a[i,1]<a[i+1,1] then
begin
z:=a[i,5];
a[i,5]:=a[i+1,5];
a[i+1,5]:=z;
y:=a[i,1];
a[i,1]:=a[i+1,1];
a[i+1,1]:=y;
x:=a[i,4];
a[i,4]:=a[i+1,4];
a[i+1,4]:=x;
end;
if a[i,1]=a[i+1,1] then
begin
if a[i,4]<a[i+1,4] then
begin
z:=a[i,5];
a[i,5]:=a[i+1,5];
a[i+1,5]:=z;
y:=a[i,1];
a[i,1]:=a[i+1,1];
a[i+1,1]:=y;
x:=a[i,4];
a[i,4]:=a[i+1,4];
a[i+1,4]:=x;
end;
end;
end;
writeln(a[i,4],' ',a[i,5]);
end;

end.
有点长，超时了， 谁给改改？

• @ 2014-08-08 18:40:29

var
yu,shu,wai,yu1,shu1,wai1:array[1..300] of integer;
i,j,k,t,s,n:longint;
zong,kong,ans:array[1..300] of longint;
begin
for i:=1 to n do
begin
yu1[i]:=yu[i];
shu1[i]:=shu[i];
wai1[i]:=wai[i];
end;
for i:=1 to n do
begin
kong[i]:=yu[i]+shu[i]+wai[i];
zong[i]:=kong[i];
end;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if (zong[i]<zong[j]) then begin
t:=zong[i];zong[i]:=zong[j];zong[j]:=t;
t:=yu1[i];yu1[i]:=yu1[j];yu1[j]:=t;
t:=shu1[i];shu1[i]:=shu1[j];shu1[j]:=t;
t:=wai1[i];wai1[i]:=wai1[j];wai1[j]:=t;
end;
end;
for i:=1 to n do
for j:=1 to n do
begin
if (zong[i]=kong[j]) and (yu1[i]=yu[j]) and (shu1[i]=shu[j]) and (wai1[i]=wai[j]) then ans[i]:=j;
end;
for i:=1 to 10 do
begin
if (zong[i]=zong[i+1]) and ((yu1[i]<yu1[i+1]) or (ans[i]>ans[i+1])) then begin
t:=zong[i];zong[i]:=zong[i+1];zong[i+1]:=t;
t:=yu1[i];yu1[i]:=yu1[i+1];yu1[i+1]:=t;
t:=ans[i];ans[i]:=ans[i+1];ans[i+1]:=t;
end;
end;
for i:=1 to 5 do
begin
writeln(ans[i],' ',zong[i]);
end;
end.

• @ 2013-08-30 09:16:11

代码有点长 但是满分！

type
jy=record
yw:longint;
ss:longint;
yy:longint;
xx:longint;
zf:longint
end;
var a:array[0..301]of jy;
i,j,l,m,n,z,y,x,t:longint;
k:jy;
begin
for i:=1 to n do
begin
a[i].xx:=i;
end;
for i:=1 to n do
a[i].zf:=a[i].yw+a[i].ss+a[i].yy;
for i:=1 to n-1 do
for j:= n-1 downto i do
if a[j].zf<a[j+1].zf then
begin
k:=a[j];
a[j]:=a[j+1];
a[j+1]:=k;
end;
for i:=1 to 5 do
begin
if a[i].zf=a[i+1].zf then
begin
if a[i].yw<a[i+1].yw then
begin
k:=a[i];
a[i]:=a[i+1];
a[i+1]:=k;
end;
if a[i].yw=a[i+1].yw then
begin
if a[i].xx>a[i+1].xx then
begin
k:=a[i];
a[i]:=a[i+1];
a[i+1]:=k; end;
end;
end;
end;
for i:=1 to 5 do
begin
write(a[i].xx,' ');
writeln(a[i].zf);
end;
end.

• @ 2013-08-03 14:16:16

program p1398;
var
a,i,j,x,z,y:integer;
zon,xu,yu:array[1..100]of integer;
procedure bijiao;
var
t,k,f:integer;
begin
k:=a;
for i:=1 to k-1 do
for j:=i+1 to k do
if zon[i]>zon[j] then
t:=zon[i];zon[i]:=zon[j];zon[j]:=t;
f:=xu[i];xu[i]:=xu[j];xu[j]:=f;
repeat
dec(k);
bijiao;
until k=0;
end;

procedure bijiao2;
var
t,k,f:integer;
begin
for i:=2 to a do
if zon[i]=zon[i-1] then
begin
if yu[i]>yu[i-1] then
begin
zon[i]:=zon[i];
zon[i-1]:=zon[i-1];
end
else
t:=zon[i]; zon[i]:=zon[i-1]; zon[i-1]:=t;
k:=xu[i]; xu[i]:=xu[i-1]; xu[i-1]:=k;
f:=yu[i]; yu[i]:=yu[i-1]; yu[i-1]:=f;
end;
end;

begin
for i:=1 to a do
xu[i]:=i;
yu[i]:=x;
zon[i]:=x+y+z;
bijiao;
bijiao2;
for i:=a downto a-5 do
writeln(xu[i],' ',zon[i]);
end.
汗--之前那个忘输出了。

• @ 2013-08-03 14:13:45

var
a,i,j,x,z,y:integer;
zon,xu,yu:array[1..100]of integer;
procedure bijiao;
var
t,k,f:integer;
begin
k:=a;
for i:=1 to k-1 do
for j:=i+1 to k do
if zon[i]>zon[j] then
t:=zon[i];zon[i]:=zon[j];zon[j]:=t;
f:=xu[i];xu[i]:=xu[j];xu[j]:=f;
repeat
dec(k);
bijiao;
until k=0;
end;

procedure bijiao2;
var
t,k,f:integer;
begin
for i:=2 to a do
if zon[i]=zon[i-1] then
begin
if yu[i]>yu[i-1] then
begin
zon[i]:=zon[i];
zon[i-1]:=zon[i-1];
end
else
t:=zon[i]; zon[i]:=zon[i-1]; zon[i-1]:=t;
k:=xu[i]; xu[i]:=xu[i-1]; xu[i-1]:=k;
f:=yu[i]; yu[i]:=yu[i-1]; yu[i-1]:=f;
end;
end;

begin
for i:=1 to a do
xu[i]:=i;
yu[i]:=x;
zon[i]:=x+y+z;
bijiao;
bijiao2;
end.

ID
1398

4

6366

2634

41%

16