用冒泡
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n;
char name[1000][105];
int age[1000],score[1000];
int i,flag;
int rank[1000];
int temp;
while(~scanf("%d",&n))
{
for(i=0;i<n;i++)
{
scanf("%s%d%d",name[i],&(age[i]),&(score[i]));
rank[i]=i;
}
flag=1;
while(flag)
{
flag=0;
for(i=1;i<n;i++)
{
if(score[rank[i-1]]>score[rank[i]])
{
if(!flag)
flag=1;
temp=rank[i];
rank[i]=rank[i-1];
rank[i-1]=temp;
}
else
{
if(score[rank[i-1]]==score[rank[i]] && strcmp(name[rank[i-1]],name[rank[i]])>0)
{
if(!flag)
flag=1;
temp=rank[i];
rank[i]=rank[i-1];
rank[i-1]=temp;
}
else
{
if(score[rank[i-1]]==score[rank[i]] && strcmp(name[rank[i-1]],name[rank[i]])==0 && age[rank[i-1]]>age[rank[i]])
{
if(!flag)
flag=1;
temp=rank[i];
rank[i]=rank[i-1];
rank[i-1]=temp;
}
}
}
}
}
for(i=0;i<n;i++)
printf("%s %d %d\n",name[rank[i]],age[rank[i]],score[rank[i]]);
}
return 0;
}