题意:给出一张许多人的年龄和生日表。你需要从年轻到年老输出人们的名字。(没有人年龄相同)
排序
//author: CHC
//First Edit Time: 2015-09-05 19:00
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const int MAXN=1e+4;
const int MAXM=1e+5;
const int INF = numeric_limits<int>::max();
const LL LL_INF= numeric_limits<LL>::max();
char str[110][200];
struct point {
int year,pos;
}cs[MAXN];
int cmp(const point &x,const point &y){
return x.year>y.year;
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++){
//scanf("%s%d",str[i],&cs[i].year);
gets(str[i]);
cs[i].year=0;
int len=strlen(str[i]);
//printf("len:%d\n",len);
for(int j=len-4;j<len;j++)cs[i].year=cs[i].year*10+str[i][j]-'0';
//printf("%d\n",cs[i].year);
str[i][len-5]=0;
cs[i].pos=i;
}
sort(cs,cs+n,cmp);
for(int i=0;i<n;i++)printf("%s\n",str[cs[i].pos]);
}
return 0;
}