Result: Accepted
Time: 14ms
Memory: 1092kB
#include<stdio.h>
#include<stdlib.h>
struct f{
char name[20];
int li;
int shi;
int amount;
};
int comp(const void * p,const void *q){
return ((struct f *)q)->amount-((struct f *)p)->amount;
}
int main(){
struct f loy[100];
int i,j,k,T,N;
scanf("%d",&T);
for(i = 1 ; i <= T ; ++ i){
scanf("%d",&N);
for(j = 0 ; j < N ; ++ j){
getchar();
scanf("%s %d %d",loy[j].name,&loy[j].li,&loy[j].shi);
loy[j].amount = loy[j].li+loy[j].shi;
}
qsort(loy,N,sizeof(struct f),comp);
for(j = 0 ; j < N ;++ j)
printf("%s\n",loy[j].name);
}
return 0;
}