#include <iostream>
#include <algorithm>
#include<string>
using namespace std;
struct student { string name; int score;
};
bool cmp0(student x, student y) { return x.score > y.score;
}
int main()
{ struct student stu[200]; int n, tag; cin >> n >> tag; for (int i = 0; i < n; i++) { cin >> stu[i].name >> stu[i].score; } if (tag == 0) stable_sort(stu, stu + n, cmp0); if (tag == 1) stable_sort(stu, stu + n, [](student x, student y) {return x.score < y.score; }); for (int i = 0; i < n; i++) cout << stu[i].name << ' ' << stu[i].score << endl;
}
知识点:结构体。sort函数