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≤ which denotes the number of test cases. For each test case, there is an positive integer n(≤n≤) which denotes the number of people,and next n 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 .Notice name only contain letter(s),digit(s) and space(s).
Output
For each case, output n lines.
Sample Input
FancyCoder FancyCoder
xyz111
Sample Output
FancyCoder
xyz111
FancyCoder
Source
具体看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define N 106
int n;
struct Node{
int year;
char ch[];
}person[N];
bool cmp(Node a,Node b){
return a.year>b.year;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
char s[];
getchar();
for(int i=;i<n;i++){
person[i].year=;
gets(s);
//puts(s);
int len=strlen(s);
for(int j=;j<len-;j++){
person[i].ch[j]=s[j];
}
person[i].ch[len-]='\0';//记得加,否则wa for(int j=len-;j<len;j++){
person[i].year=person[i].year*+s[j]-'';
}
//printf("%s\n",person[i].ch);
//printf("%d\n",person[i].year);
}
sort(person,person+n,cmp);
for(int i=;i<n;i++){
printf("%s\n",person[i].ch);
}
} return ;
}