#include<iostream>
#include<cstring>
using namespace std;
#include<cstdio>
struct node{
char name[30];
int score;
};
node student[22];
int main()
{
int n,i,j;
cin>>n;
for(i=1;i<=n;i++)
cin>>student[i].name>>student[i].score;
for(i=n-1;i>=1;i--)
for(j=1;j<=i;j++)//条件需要写清楚,这里很容易出错,冒泡法排序的起点和终点需要明确,便利很容易超出范围
{ if(student[j].score<student[j+1].score)
swap(student[j],student[j+1]);
else if((student[j].score==student[j+1].score)&&(strcmp(student[j].name,student[j+1].name)>0))
swap(student[j],student[j+1]);
}
for(i=1;i<=n;i++)
cout<<student[i].name<<" "<<student[i].score<<endl;//这里使用了 printf语句始终无法通过遍历 一本通上的cin和cout必须配对才能通过编译。
return 0;
}