题意:按照年龄从小到大排序
名字中可能有空格什么的,处理下即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define maxn 105
#define mod 1000000007
char tt[150];
struct node
{
int x;
char id[105];
} pnode[maxn]; bool cmp(node a,node b)
{
return a.x > b.x;
}
int main()
{
int T;
scanf("%d",&T);
getchar();
while(T--)
{
int n;
scanf("%d",&n);
getchar();
for(int i = 1; i <= n; i++)
{
gets(tt); int len = strlen(tt);
int num = 0;
for(int j = len-4; j < len; j++)
num = num*10+(tt[j] - '0');
pnode[i].x = num;
for(int j = 0;j < len - 5;j++)
pnode[i].id[j] = tt[j];
pnode[i].id[len-5] = '\0';
}
sort(pnode+1,pnode+n+1,cmp);
for(int i = 1;i <= n;i++)
printf("%s\n",pnode[i].id);
}
return 0;
}