幽灵特工 @ 2020-07-25 11:50:42
#include<bits/stdc++.h>
using namespace std;
class student {
public:
int number;
int c, m, e;
int sum;
};
bool cmp(student a, student b) {
if (a.sum < b.sum) {
return 1;
}
else if (a.sum == b.sum) {
if (a.c < b.c) {
return 1;
}
if (a.number < b.number) {
return 1;
}
}
else return 0;
}
int main()
{
int n;
student stu[301];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> stu[i].c >> stu[i].m >> stu[i].e;
stu[i].sum = stu[i].c + stu[i].m + stu[i].e;
}
sort(stu, stu + n,cmp);
for (int i = 0; i < 5; i++) {
cout << stu[i].number << stu[i].sum << endl;
}
return 0;
}
by konjacq @ 2020-07-25 11:55:27
if (a.number < b.number)
加一个&&a.c==b.c
by 幽灵特工 @ 2020-07-25 11:57:49
@konjacq 没用哦
by konjacq @ 2020-07-25 11:59:04
@幽灵特工 而且您大小于打反了几个吧
by konjacq @ 2020-07-25 12:00:14
stu[i].number
没有初值
by 幽灵特工 @ 2020-07-25 12:00:21
@konjacq 额,是哪里打反了呢
by konjacq @ 2020-07-25 12:00:32
stu[i].number
差个空格
by konjacq @ 2020-07-25 12:01:25
@幽灵特工 您总共就三个大小于不能自己试?
by konjacq @ 2020-07-25 12:01:48
说错了,是cout << stu[i].number << stu[i].sum << endl;
差空格
by 幽灵特工 @ 2020-07-25 12:09:59
@konjacq 嗯好,谢谢了,我再自己琢磨一下