排序 年轻的排前面 名字中可能有空格
Sample Input
21FancyCoder 19962FancyCoder 1996xyz111 1997Sample Output
FancyCoderxyz111FancyCoder
1 # include2 # include 3 # include 4 # include 5 # include 6 # include 7 # include 8 # define LL long long 9 using namespace std ;10 11 struct ren12 {13 char name[200] ;14 int age ;15 }a[120];16 17 bool cmp(ren x , ren y)18 {19 return x.age > y.age ;20 }21 22 int main ()23 {24 //freopen("in.txt","r",stdin) ;25 int T ;26 scanf("%d" , &T) ;27 while(T--)28 {29 int n , i ;30 scanf("%d" , &n) ;31 getchar() ;32 for (i = 0 ; i < n ; i++)33 {34 gets(a[i].name) ;35 int len = strlen(a[i].name) ;36 sscanf(&a[i].name[len-5] , "%d" , &a[i].age);37 a[i].name[len-5] = '\0' ;38 }39 40 sort(a , a+n , cmp) ;41 for (i = 0 ; i < n ; i++)42 printf("%s\n" , a[i].name) ;43 44 }45 46 return 0 ;47 }