讨论 / c++ sort
2624521995 2016-07-12 21:03:22
点我顶贴 收藏 删除
#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<iostream>

using namespace std;

struct stu{

int yw;

int sx;

int yy;

int xh;

int zf;

};

bool cmp(stu c,stu b){

if(c.zf!=b.zf)

return c.zf>b.zf;

else

{

if(c.yw!=b.yw)

return c.yw>b.yw;

else

return c.xh<b.xh;

}

}

int main()

{

int n;

struct stu a[10000];

scanf("%d",&n);

for(int i=0;i<n;i++)

{

a[i].xh=i;

scanf("%d %d %d",&a[i].yw,&a[i].sx,&a[i].yy);

a[i].zf=a[i].yw+a[i].sx+a[i].yy;

}

sort(a,a+n,cmp);

for(int i=0;i<5;i++)

printf("%d %d\n",a[i].xh+1,a[i].zf);

return 0;

}

查看更多回复
提交回复