#include<stdio.h>
#define N 15
//思路:使用结构体。定义三个结构体变量temp, max, min,然后分别对输入的每一个学生的成绩进行判断,
// 如果temp.score>max.score,将temp整体赋值给max,如果temp.score<min.score,将将temp整体赋值给min。
// 最后打印结果即可。
struct student //定义结构体数据类型
{
char name[N];
char id[N];
int score;
};
int main(void)
{
int i, j, n;
struct student temp, max, min;
scanf("%d\n", &n);
max.score = -1; //设置的方式很好 max.score一定大于-1
min.score = 101;
for (i = 0; i < n; i++)
{
scanf("%s%s%d",temp.name, temp.id, &temp.score);
if (temp.score > max.score)
{
max = temp; //将结构体变量temp整体赋值给max
}
if (temp.score < min.score)
{
min = temp; //将结构体变量temp整体赋值给min
}
}
printf("%s %s\n", max.name, max.id);
printf("%s %s\n", min.name, min.id);
return 0;
}
1004. 成绩排名 (20)
最新推荐文章于 2021-03-01 23:44:24 发布