文章

145

粉丝

143

获赞

21

访问

40.5k

头像
成绩排序 - 华科 题解:C
P1404 华中科技大学
发布于2024年2月11日 21:18
阅读数 505

#include <stdio.h>
#include <string.h>

typedef struct{
	char s[101];
	int age;
	float grade;
}Student;

void Sort(Student stu[],int n)
{
	int i,j;
	Student t;
	for(i = 0; i < n-1; i++)
		for(j = 1; j < n-i; j++)
			if(stu[j].grade < stu[j-1].grade)
			{
				t = stu[j];
				stu[j] = stu[j-1];
				stu[j-1] = t;
			}
			else if(stu[j].grade == stu[j-1].grade)
			{
				if(strcmp(stu[j].s,stu[j-1].s) < 0)
				{
					t = stu[j];
					stu[j] = stu[j-1];
					stu[j-1] = t;
				}
				else if(strcmp(stu[j].s,stu[j-1].s) == 0)
				{
					if(stu[j].age < stu[j-1].age)
					{
						t = stu[j];
						stu[j] = stu[j-1];
						stu[j-1] = t;
					}
				}
			}
}

int main()
{
	Student stu[1000];
	int i,n;
	while(scanf("%d",&n) != EOF)
	{
		for(i = 0; i < n; i++)
			scanf("%s %d %f",stu[i].s,&stu[i].age,&stu[i].grade);
		Sort(stu,n);
		for(i = 0; i < n; i++)
			printf("%s %d %g\n",stu[i].s,stu[i].age,stu...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发