#include<iostream>
#include<conio.h>
#include<fstream>
#include<sstream>
#define null 0
using namespace std;
int main(){
struct stu{
long num;
string name;
stu *next;};
struct stu *head,*h1,*h2;
h1=h2=new stu;
cin>>h1->num>>h1->name;
head=null;
int n=0;
while(h1->num!=0){
   n=n+1;
   if(n==1)head=h1;
   else h2->next=h1;
   h2=h1;
   h1=new stu;
   cin>>h1->num>>h1->name;   
  }
  h2->next=null;
 h1=head;
  if(head!=null)
   do{cout<<h1->num<<" "<<h1->name<<endl;
   h1=h1->next;
   }while(h1!=null);
  cout<<"请输入要插入的人名:\n" ;
  stu *s;
  s=new stu;
  cin>>s->num>>s->name;
  h1=head;
  if(head==null){head=s;s->next=null;}
  else
  {
      while((s->num>h1->num)&&(h1->next!=null)){
                                                h2=h1; h1=h1->next;}
     if(s->num<=h1->num){
                         if(head==h1){head=s;s->next=h1;}
                         else {h2->next=s;s->next=h1;}}
     else{h1->next=s;s->next=null;}
     }
  h1=head;
  if(head!=null)
   do{cout<<h1->num<<" "<<h1->name<<endl;
   h1=h1->next;
   }while(h1!=null);
                                            getch();
                                            return 0;
                                            }