sort函数是不稳定的排序
by QWQ_123456fyy @ 2022-08-01 20:31:35
```
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
using namespace std;
struct student {
char name[10];
int a,b,c,sum,id;
};
bool cmp(student tmp2,student tmp3) {
if(tmp2.sum == tmp3.sum)return tmp2.id < tmp3.id ;//如果有总分相同的学生,输出靠前的那位。
return tmp2.sum > tmp3.sum;
}
student tmp[1100];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tmp[i].name >> tmp[i].a >> tmp[i].b >> tmp[i].c;
tmp[i].sum = tmp[i].a + tmp[i].b + tmp[i].c;
tmp[i].id= i ;
}
sort(tmp, tmp + n, cmp);
cout << tmp[0].name <<" "<< tmp[0].a <<" "<< tmp[0].b <<" "<< tmp[0].c;
}
```
by QWQ_123456fyy @ 2022-08-01 20:39:59
@[jisp123](/user/450482)
by QWQ_123456fyy @ 2022-08-01 20:41:49
@[123456fyy](/user/690507) 谢了,明白了
by jisp123 @ 2022-08-01 22:19:53