1004. 成绩排名 (20)
原题: https://www.patest.cn/contests/pat-b-practise/1004
实现思路: 利用结构体定义学生信息, 简单循环即可实现功能. 注意, 本题最好不要使用
结构指针.
完整代码:
#include <stdio.h>
struct student {
char name[20];
char no[20];
int score;
};
typedef struct student s_student; // 最好别用结构指针, 否则老麻烦了
int main () {
s_student high; // 最高的学生
s_student low; // 最低分学生
s_student temp; // 遍历学生信息, 临时用
int n;
scanf("%d", &n);
scanf("%s %s %d", high.name, high.no, &high.score);
low = high; // 第一个数据, 作为初始值
n--;
while (n) {
scanf("%s %s %d", temp.name, temp.no, &temp.score);
if (high.score < temp.score) {
high = temp;
}
if (low.score > temp.score) {
low = temp;
}
n--;
}
printf("%s %s\n", high.name, high.no);
printf("%s %s\n", low.name, low.no);
return 0;
}
/*
输入:
3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95
输出:
Mike CS991301
Joe Math990112
*/
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步