aniuge @ 2017-08-23 18:34:41
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int hao=0,yu=0,shu=0,wai=0,zong=0;
}a[400];
int cmp(node s,node b)
{
if(s.zong>b.zong) return 1;
if(s.zong<b.zong) return 0;
if(s.yu>b.yu) return 1;
if(s.yu<b.yu) return 0;
if(s.hao<b.hao) return 1;
if(s.hao>b.hao) return 0;
}
int main()
{
int n;
while(cin>>n)
{
for(int i=1;i<=n;i++)
{
a[i].hao=i;
cin>>a[i].yu>>a[i].shu>>a[i].wai;
a[i].zong=a[i].yu+a[i].shu+a[i].wai;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++)
{
cout<<a[i].hao<<" "<<a[i].zong<<endl;
}
}
}
by 贺啸风 @ 2017-09-24 17:39:42
直接用选排思路会更清晰,快排函数容易错
by 青衫白叙 @ 2017-09-26 22:24:26
快排还不好啊。。。。
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{int cnt, y, id;}a[301];
bool cmp(node a,node b)
{return a.cnt > b.cnt || (a.cnt == b.cnt && a.y > b.y) || (a.cnt == b.cnt && a.y == b.y && a.id < b.id);}
int main() {
int n,x,y,z;scanf("%d",&n);
for(int i=0; i<n; ++i) {
scanf("%d%d%d",&x,&y,&z);
a[i] = (node){x+y+z,x,i};
}
sort(a,a+n,cmp);
for(int i=0;i<5; ++i) printf("%d %d\n",a[i].id+1,a[i].cnt);
return 0;
}
by fletmer @ 2017-10-04 00:15:27
第九个点我快排两遍才过