您的位置:首页 > 其它

A problem of sorting

2015-09-05 20:55 363 查看
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 100T≤100 which denotes the number of test cases.

For each test case, there is an positive integer n (1 \leq n \leq 100)n(1≤n≤100) 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


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct p
{
int eag;
char name[105];
};p s[105];
bool com(p A,p B)
{
return A.eag>B.eag;
}
int pow(int x,int y)
{
int n=1,i;
for (i=0;i<y;i++) n*=x;
return n;
}
int main()
{
int t,n,n2,i,l,j,k;
char ss[205];
scanf("%d",&t);
while (t--)
{
k=0;
scanf("%d",&n);
n2=n;
getchar();
while (n--)
{
j=0;
s[k].eag=0;
gets(ss);
l=strlen(ss);
for (i=l-1;i>=0;i--)
{
if (ss[i]==' ') break;
s[k].eag+=(ss[i]-'0')*pow(10,j);
j++;
}
//  printf("%d\n",s[k].eag);
for (j=0;j<i;j++) s[k].name[j]=ss[j];
s[k].name[j]='\0';
k++;
}
sort(s,s+n2,com);
for (i=0;i<n2;i++) printf("%s\n",s[i].name);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: