#include <iostream> #include<algorithm>//sort函数头文件 using namespace std; struct Student {//定义student结构体 int number; int score; bool operator<(Student student)const {//运算符<重载,定义一个新的stunde比较,const表示运算符重载不会改变对象的状态 if (score == student.score) { return number < student.number; } else { return score < student.score; } } }; int main() { int N; cin >> N; Student arr[100]; for (int i = 0; i < N; ++i) { cin >> arr[i].number >> arr[i].score; } sort(arr, arr + N); for (int i = 0; i < N; ++i) { std::cout << arr[i].number << ' ' << arr[i].score << std::endl; } }