Dark_Kotori @ 2017-03-05 10:43:32
#include<iostream>
using namespace std;
int name[1000],chi[1000],sum[1000];
void zh(int i,int j){
int p;
p=sum[i];
sum[i]=sum[j];
sum[j]=p;
p=chi[i];
chi[i]=chi[j];
chi[j]=p;
p=name[i];
name[i]=name[j];
name[j]=p;
}
void qsort(int l,int r){
int i,j,mid,p;
i=l;j=r;
mid=sum[(l+r)/2];
do{
while(sum[i]>mid) i++;
while(sum[j]<mid) j--;
if(i<=j){
zh(i,j);
i++;
j--;
}
}while(i<=j);
if(l<j) qsort(l,j);
if(l<r) qsort(i,r);
}
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n;
cin>>n;
for(int i=1;i<=n;i++){
int chin,math,eng;
name[i]=i;
cin>>chin>>math>>eng;
chi[i]=chin;
sum[i]=chin+math+eng;
}
qsort(1,n);
for(int i=1;i<=n;i++){
if(sum[i]==sum[i+1]){
if(chi[i]==chi[i+1]&&name[i+1]<name[i]) zh(i,i+1);
else if(chi[i]<chi[i+1]) zh(i,i+1);
}
}
for(int i=1;i<=5;i++) cout<<name[i]<<' '<<sum[i]<<endl;
}
by zhengzha @ 2017-04-27 13:01:41
#include<cstdio>
#include<cstdlib>
#include<cstring>
int n,m;
struct node{int x,y,z,g,b;};
node a[310];
int z=0;
bool tf=false;
void qsort(int l,int r)
{
int i,j;
int m;
node t;
i=l;j=r;
m=a[(l+r)/2].g;
while (i<=j)
{
while (a[i].g>m) i++;
while (a[j].g<m) j--;
if (i<=j)
{
t=a[i];a[i]=a[j];a[j]=t;
i++;j--;
}
}
if (l<j) qsort(l,j);
if (i<r) qsort(i,r);
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].z);
a[i].g=a[i].x+a[i].y+a[i].z;
a[i].b=i;
}
qsort(1,n);
for (int i=1;i<n;i++)
{
if (a[i].g==a[i+1].g)
{
if (a[i].x<a[i+1].x)
{
node t;
t=a[i];a[i]=a[i+1];a[i+1]=t;
}
else if (a[i].x==a[i+1].x)
{
if (a[i].b>a[i+1].b)
{
node t;
t=a[i];a[i]=a[i+1];a[i+1]=t;
}
}
}
}
for (int i=1;i<=5;i++)
printf("%d %d\n",a[i].b,a[i].g);
}//如题
by LDXOUN7 @ 2017-04-27 14:15:04
#include"bits/stdc++.h"
using namespace std;
struct jxj
{
int c,s,e,h,t;
};
jxj m[10001];
bool a(jxj &a,jxj &b)
{
if(a.t>b.t)return 1;
if(a.t==b.t&&a.c>b.c)
return 1;
if(a.t==b.t&&a.c==b.c&&a.h<b.h)return 1;
return 0;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>m[i].c>>m[i].s>>m[i].e;
m[i].h=i;
m[i].t=m[i].c+m[i].s+m[i].e;
}
sort(m+1,m+n+1,a);
for(int i=1;i<=5;i++)
cout<<m[i].h<<" "<<m[i].t<<endl;
return 0;
}