吕东润 @ 2019-12-06 19:31:42
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int chinese[305],math[305],english[305];
struct node{
int a,b,c;
}zong[305];
bool cmp(node a,node b){
return a.a>b.a;
}
void cm(node a,node b){
swap(a.a,b.a);
swap(a.b,b.b);
swap(a.c,b.c);
return ;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>chinese[i]>>math[i]>>english[i];
zong[i].c=i;
zong[i].a=chinese[i]+math[i]+english[i];
zong[i].b=chinese[i];
}
sort(zong+1,zong+n+1,cmp);
for(int i=1;i<=n;i++){
if(zong[i].a==zong[i+1].a){
if(zong[i].b<zong[i+1].b){
cm(zong[i],zong[i+1]);
// swap(zong[i].c,zong[i+1].c);
}
}
}
for(int i=1;i<=5;i++){
cout<<zong[i].c<<" "<<zong[i].a<<endl;
}
return 0;
}
//19 90 94 86
//101 86 98 86
//88 98 70 54
by xieshanling @ 2019-12-06 20:03:18
@吕东润 总分和语文成绩都相同时,学号小的要排在前面
by 吕东润 @ 2019-12-06 20:15:05
@C_wind
by 吕东润 @ 2019-12-06 20:16:42
不用吧,我是已经按总分排序(默认是学号从小到大)如果总分和语文成绩都相同时,就不交换,所以不用给学号排序
by 编程萌新or大神 @ 2019-12-08 11:39:59
@吕东润 默认??
by Pine_applee @ 2020-01-08 20:26:39
@吕东润 感谢大佬的讲解 ——来自同样五十分的蒟蒻