题目:(王道 1061)

有N个学生的数据,将学生数据按成绩高低排序,如果成绩相同则按姓名字符的字母序排序,如果姓名的字母序也相同则按照学生的年龄排序,并输出N个学生排序后的信息。

输入:   

 测试数据有多组,每组输入第一行有一个整数N(N<=1000),接下来的N行包括N个学生的数据。  每个学生的数据包括姓名(长度不超过100的字符串)、年龄(整形数)、成绩(小于等于100的正数)。

输出:

将学生信息按成绩进行排序,成绩相同的则按姓名的字母序进行排序。然后输出学生信息,按照如下格式: 姓名 年龄 成绩

输入:

3 abc 20 99 bcd 19 97 bed 20 97

输出:


bcd 19 97 bed 20 97 abc 20 99


#include <stdio.h>
#include <string.h>
struct student
{
char name[100];
int age;
int score;
}stuOne[1000];
int main()
{
int n,i,j;
struct student temp;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%s%d%d",stuOne[i].name,&stuOne[i].age,&stuOne[i].score);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(stuOne[j].score>stuOne[j+1].score)
{
temp=stuOne[j];
stuOne[j]=stuOne[j+1];
stuOne[j+1]=temp;
}
else if(stuOne[j].score==stuOne[j+1].score)
{
if(strcmp(stuOne[j].name,stuOne[j+1].name)>0)
{
temp=stuOne[j];
stuOne[j]=stuOne[j+1];
stuOne[j+1]=temp;
}
}
}
}
for(i=0;i<n;i++)
{
printf("%s %d %d\n",stuOne[i].name,stuOne[i].age,stuOne[i].score);
}
}
return 0;
}