Result: Accepted
Time: 11ms
Memory: 1092kB
#include<stdio.h>
#include<stdlib.h>
#define ARRAY_SIZE 100
struct student
{
char name[30];
int score[2];
int total;
};
int comp(const void * p,const void * q)
{
return ((struct student *)q)->total-((struct student *)p)->total;
}
int main()
{
struct student studentArray[ARRAY_SIZE];
int i,n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=0;i<n;++i)
{
scanf("%s%d%d",studentArray[i].name,&studentArray[i].score[0],&studentArray[i].score[1]);
studentArray[i].total=studentArray[i].score[0]+studentArray[i].score[1];
}
qsort(studentArray,n,sizeof(struct student),comp);
for(i=0;i<n;++i)
{
printf("%s\n",studentArray[i].name);
}
}
return 0;
}