您的位置:首页 > 其它

hdu 5427(水)

2015-10-02 14:49 337 查看
题意:按照年龄从小到大排序

名字中可能有空格什么的,处理下即可

#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;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: