讨论 / C++ STL sort函数版
DavidTesla 2016-06-24 16:20:04
点我顶贴 收藏 删除
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

struct str{

int num;

int c;

int m;

int e;

int sum;

}student[300];

bool cmp(str A,str B);

int main()

{

int n;

scanf("%d",&n);

for(int q=1;q<=n;q++){

scanf("%d%d%d",&student[q].c,&student[q].m,&student[q].e);

student[q].sum=student[q].c+student[q].m+student[q].e;

student[q].num=q;

}

sort(student+1,student+n+1,cmp);

for(int q=1;q<=5;q++)

printf("%d %d\n",student[q].num,student[q].sum);

return 0;

}

bool cmp(str A,str B)

{

if(A.sum!=B.sum)

return A.sum>B.sum;

else if(A.c!=B.c)

return A.c>B.c;

else

return A.num<B.num;

}

查看更多回复
提交回复