/*
题目大意很清楚,水题
*/
# include <stdio.h>
struct Student
{
int id;
int grade;
};
void sort(Student * stu, int num)
{
Student temp;
int i,j;
for(i = 0; i < num; i++)
{
for(j = 0; j < num-1; j++)
{
if(stu[j].grade > stu[j+1].grade)
{
temp = stu[j];
stu[j] = stu[j+1];
stu[j+1] = temp;
}
if((stu[j].grade == stu[j+1].grade) && (stu[j].id > stu[j+1].id))
{
temp = stu[j];
stu[j] = stu[j+1];
stu[j+1] = temp;
}
}
}
}
int main(void)
{
int num;
Student stu[100];
while(scanf("%d",&num) != EOF)
{
getchar(); //吸收回车符。
if(num <= 0) break;
int i;
for(i = 0; i < num; i++)
{
scanf("%d %d", &stu[i].id, &stu[i].grade);
}
sort(stu, num);
for(i = 0; i < num; i++)
{
printf("%d %d\n", stu[i].id, stu[i].grade);
}
}
return 0;
}
1196 成绩排序
最新推荐文章于 2022-09-24 18:18:28 发布