#include using namespace std; struct Student { string name; int score; }; //对比的方法 /* 用大于号就是从大到小排序,用小于号就是从小到大排序 */ bool compare(const Student &x, const Student &y) { if (x.score == y.score) return x.name < y.name; return x.score > y.score; } int main() { int n; cin >> n; Student *s = new Student[n]; for (int i = 0; i < n; ++i) { cin >> s[i].name >> s[i].score; } //排序 sort(s, s + n, compare); //输出 for (int i = 0; i < n; ++i) { cout << s[i].name << " " << s[i].score << endl; } //删除动态创建的指针数组 delete[]s; return 0; }