酷代码 AI
菜单

用C语言写 :3-2 寻找学习之星 分数 15 2024级评选学习之星一名,要求:(1) 3门课考试总成绩前两位满足条件(排名第一的优先考虑,排名第二的备选);(2) 综合评议得分,超过学习之星的小于全体学生的50%。 若以上两个要求不能同时满足,则无人当选。 注:(1)为了便于处理,假设没有3门课总成绩同分的情况;(2)学号为位数小于9位的任意整数。 输入格式: 第一行输入学生总人数n; 第二行开始每行以格式“学号 3门课考试成绩 综合评议得分”输入n个学生的成绩(共n行)。 输出格式: 有人当选,输出当选学习之星的学生学号,否则,输出“No students meet the requirements!”。 输入样例1: 5 23001 45 60 70 80 23002 99 99 99 79 23003 80 60 60 90 23004 97 90 90 79 23005 97 90 91 80 输出样例1: The student ID of Learning Star is 23005 输入样例2: 5 23001 45 60 70 81 23002 99 99 9

```c #include <stdio.h> #define MAX_STUDENTS 1000 typedef struct { int id; int scores[3]; int total_score; int evaluation_score; } Student; // 比较函数,用于qsort按总成绩降序排序 int compare(const void *a, const void *b) { Student *studentA = (Student *)a; Student *studentB = (Student *)b; return studentB->total_score - studentA->total_score; } int main() { int n; Student students[MAX_STUDENTS]; // 输入学生总人数 scanf("%d", &n); // 输入每个学生的信息 for (int i = 0; i < n; i++) { scanf("%d %d %d %d %d", &students[i].id, &students[i].scores[0], &students[i].scores[1], &students[i].scores[2], &students[i].evaluation_score); students[i].total_score = students[i].scores[0] + students[i].scores[1] + students[i].scores[2]; } // 按总成绩降序排序 qsort(students, n, sizeof(Student), compare); // 检查前两名学生 for (int i = 0; i < 2 && i < n; i++) { int count = 0; // 统计综合评议得分超过当前学生的人数 for (int j = 0; j < n; j++) { if (students[j].evaluation_score > students[i].evaluation_score) { count++; } } // 判断是否满足综合评议得分条件 if (count < n / 2) { printf("The student ID of Learning Star is %d\n", students[i].id); return 0; } } // 若都不满足条件 printf("No students meet the requirements!\n"); return 0; } ``` [2025-12-29 18:37:42 | AI问答 | 471点数解答]

服务商
相关提问
发财导航,免费问AI
实用工具查看更多