dangchuncn @ 2022-08-26 20:30:02
#include <bits/stdc++.h>
using namespace std;
struct Student{
int num;
int c,m,e;
int score;
};
bool cmp(Student a,Student b){
if(a.score>b.score) return 1;
else if(a.score<b.score) return 0;
else{
if(a.c>b.c) return 1;
else if(a.c<b.c) return 0;
else{
if(a.num>b.num) return 1;
else return 0;
}
}
}
int main(){
int n,cn,eg,ma;
struct Student a[310];
cin>>n;
for(int i=1;i<=n;i++){
a[i].num=i;
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].score=a[i].c+a[i].m+a[i].e;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].num<<" "<<a[i].score<<endl;
}
}
by _HCl_ @ 2022-08-26 20:38:04
if(a.num>b.num) return 1;
这里是小于号。学号小的排前面
by gugusbx @ 2022-08-26 20:50:53
17行改为等号改为小于号。
题目要求:学号小的在前
by dangchuncn @ 2022-08-31 15:12:14
@hank123 谢谢,达瓦里氏
by dangchuncn @ 2022-08-31 15:12:33
@gugusbx 谢谢,过了