Problem Description

There are many people's name and birth in a list.Your task is to print the name from young to old.(There is no pair of two has the same age.)

Input

First line contains a single integer T \leq 100T100 which denotes the number of test cases.

For each test case, there is an positive integer n (1 \leq n \leq 100)n(1n100) which denotes the number of people,and next nn lines,each line has a name and a birth's year(1900-2015) separated by one space.

The length of name is positive and not larger than 100100.Notice name only contain letter(s),digit(s) and space(s).

Output

For each case, output nn lines.

Sample Input
2
1
FancyCoder 1996
2
FancyCoder 1996
xyz111 1997
Sample Output
FancyCoder
xyz111
FancyCoder

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 struct p
 6 {
 7     int eag;
 8     char name[105];
 9 };p s[105];
10 bool com(p A,p B)
11 {
12     return A.eag>B.eag;
13 }
14 int pow(int x,int y)
15 {
16     int n=1,i;
17     for (i=0;i<y;i++) n*=x;
18     return n;
19 }
20 int main()
21 {
22     int t,n,n2,i,l,j,k;
23     char ss[205];
24     scanf("%d",&t);
25     while (t--)
26     {
27         k=0;
28         scanf("%d",&n);
29         n2=n;
30         getchar();
31         while (n--)
32         {
33             j=0;
34             s[k].eag=0;
35             gets(ss);
36             l=strlen(ss);
37             for (i=l-1;i>=0;i--)
38             {
39                 if (ss[i]==' ') break;
40                 s[k].eag+=(ss[i]-'0')*pow(10,j);
41                 j++;
42             }
43           //  printf("%d\n",s[k].eag);
44             for (j=0;j<i;j++) s[k].name[j]=ss[j];
45             s[k].name[j]='\0';
46             k++;
47         }
48         sort(s,s+n2,com);
49         for (i=0;i<n2;i++) printf("%s\n",s[i].name);
50     }
51 }

 

posted on 2015-09-05 20:55  pb2016  阅读(275)  评论(0编辑  收藏  举报