You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
709 B

1 year ago
#include <bits/stdc++.h>
using namespace std;
1 year ago
// 学生的结构体
struct Node {
string name;
int math;
int english;
};
// 函数实现
bool cmp(Node &a, Node &b) {
if (a.math == b.math)
return a.english > b.english; // math相等按endlish从大到小排序23
return a.math > b.math; // 按math从大到小排序
}
1 year ago
int main() {
1 year ago
// 先按math从大到小排序math相等按english从大到小排序
Node a[4] = {{"XiaoMing", 67, 89}, {"LiLei", 90, 56}, {"ZhaoSi", 90, 99}};
sort(a, a + 3, cmp);
1 year ago
1 year ago
for (int i = 0; i < 3; i++)
cout << a[i].name << " " << a[i].math << " " << a[i].english << endl;
1 year ago
return 0;
}