#include <iostream> #include <algorithm> using namespace std; struct Student { int id; int score; }; Student stu[101]; bool compare (Student x ,Student y){ if (x.score == y.score){ return x.id < y.id; } return x.score < y.score; } int main () { int n; while (cin >> n){ for (int i = 0; i < n; i++){ cin >> stu[i].id >> stu[i].score; } sort (stu, stu + n, compare); for (int i = 0; i < n; i++){ cout << stu[i].id << " " << stu[i].score << endl; } } return 0; }