kevin0574 @ 2025-01-07 21:15:40
大佬求助,回答者闭关
#include<iostream>
#include<algorithm>
using namespace std;
int n;
struct node{
int xuehao;
int y,s,e;
int sum;
}a[310];
bool cmp(node x,node y){
if(x.sum > y.sum) return true;
else if(x.sum < y.sum) return false;
else{
if(x.y > y.y) return true;
else if(x.y < y.y) return false;
else{
if(x.xuehao > y.xuehao) return true;
else if(x.xuehao < y.xuehao) return false;
}
}
}
int main(){
cin >> n;
for(int i = 1;i <= n;i++){
a[i].xuehao = i;
cin >> a[i].y >> a[i].s >> a[i].e;
a[i].sum = a[i].y + a[i].s + a[i].e;
}
sort(a+1,a+n+1,cmp);
for(int i = 1;i <= 5;i++){
cout << a[i].xuehao << " " << a[i].sum << endl;
}
return 0;
}
by wmy185486abc @ 2025-01-10 13:46:07
@kevin0574题目规定学号小的在前面,你的cmp中写成了学号大的在前面