Result: Accepted
Time: 3ms
Memory: 1120kB
#include<stdio.h>
#include<string.h>
struct student{
char name[21];
int pl;
};
int main()
{
int t;
scanf("%d",&t);
int pp=0;
for(pp=0;pp<t;pp++){
int n;int i;
scanf("%d",&n);
struct student best[101];
for(i=0;i<n;i++){
scanf("%s %d",&best[i].name ,&best[i].pl );
}
int a[101];
for(i=0;i<n;i++){
a[i]=best[i].pl;
}
int j,size=n;
for(i=0;i<size-1;i++){
int tempmin=i;
for(j=i+1;j<size;j++){
if(a[j]<a[tempmin]){
tempmin=j;
}
}
int tmp=a[i];
a[i]=a[tempmin];
a[tempmin]=tmp;
int tmp1=best[i].pl ;
best[i].pl =best[tempmin].pl ;
best[tempmin].pl =tmp1;
char temp2[21];
strcpy(temp2,best[i].name );
strcpy(best[i].name ,best[tempmin].name );
strcpy(best[tempmin].name ,temp2);
}
for(i=n-1;i>=0;i--){
printf("%s\n",best[i].name );
}
}
return 0;
}