fanqianyi @ 2021-02-12 18:51:24
#include<stdio.h>
struct man{
int ch=0;
int ma=0;
int en=0;
int sum=0;
int rec;
};
int qsort(struct man a[],int low,int high);
int partition(struct man a[],int low,int high);
int main()
{
int n,i,j,k;
struct man temp;
struct man a[305];
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d %d %d",&a[i].ch,&a[i].ma,&a[i].en);
a[i].sum=a[i].ch+a[i].ma+a[i].en;
a[i].rec=i;
}
qsort(a,1,n);
for(i=1;i<=5;i++){
for(j=i+1;j<=5;j++){
if(a[i].sum==a[j].sum){
if(a[i].ch<a[j].ch||a[i].ch==a[j].ch&&a[i].rec>a[j].rec){
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
}
for(i=1;i<=5;i++){
printf("%d %d\n",a[i].rec,a[i].sum);
}
return 0;
}
int qsort(struct man a[],int low,int high)
{
int spot;
if(low<high){
spot=partition(a,low,high);
qsort(a,low,spot-1);
qsort(a,spot+1,high);
}
}
int partition(struct man a[],int low,int high)
{
int i,j,spot;
struct man temp;
for(i=low-1,j=low,spot=a[high].sum;j<=high-1;j++){
if(a[j].sum>spot){
temp=a[j];
a[j]=a[++i];
a[i]=temp;
}
}
temp=a[high];
a[high]=a[++i];
a[i]=temp;
return i;
}