#include<bits/stdc++.h>
using namespace std;
struct Stu
{
char name[25];
int score;
};
bool isPrior(Stu &a, Stu &b)
{
return a.score > b.score || a.score == b.score && strcmp(a.name, b.name) < 0;
}
int main()
{
Stu stu[25];
int n;
cin >> n;
for(int i = 1; i <= n; ++i)
cin >> stu[i].name >> stu[i].score;
for(int i = 1; i <= n-1; ++i)
for(int j = 1; j <= n-i; ++j)
if(isPrior(stu[j+1], stu[j]))
swap(stu[j], stu[j+1]);
for(int i = 1; i <= n; ++i)
cout << stu[i].name << ' ' << stu[i].score << endl;
return 0;
}
/*
【输入样例】
4
Kitty 80
Hanmeimei 90
Joey 92
Tim 28
【输出样例】
Joey 92
Hanmeimei 90
Kitty 80
Tim 28
*/
11-05