解题思路:
注意事项:
1、最高分的学生不一定只有一个
参考代码:
#include<stdio.h> #include<malloc.h> typedef struct _student_info_ { char s_id[16]; char s_name[32]; int s_score[3]; }student_info; void input(student_info *L) { scanf("%s %s %d %d %d", L->s_id, L->s_name, &(L->s_score[0]), &(L->s_score[1]), &(L->s_score[2])); } int main() { student_info *list; int n = 0, i = 0, sum = 0, max = 0; float ave_1 = 0.0, ave_2 = 0.0, ave_3 = 0.0; scanf("%d", &n); while(getchar() != '\n') continue; if(n > 0) list = (student_info *)malloc(sizeof(student_info)*n); else return 0; for(i = 0; i < n; i++) { input(&list[i]); while(getchar() != '\n') continue; } for(i = 0; i < n; i++) { ave_1+=list[i].s_score[0]; ave_2+=list[i].s_score[1]; ave_3+=list[i].s_score[2]; sum = list[i].s_score[0]+list[i].s_score[1]+list[i].s_score[2]; if(sum > max) { max = sum; } } ave_1 = ave_1/n; ave_2 = ave_2/n; ave_3 = ave_3/n; printf("%.2f %.2f %.2f\n", ave_1, ave_2, ave_3); for(i = 0; i < n; i++) { sum = list[i].s_score[0]+list[i].s_score[1]+list[i].s_score[2]; if(sum == max) printf("%s %s %d %d %d\n", list[i].s_id, list[i].s_name, list[i].s_score[0], list[i].s_score[1], list[i].s_score[2]); } free(list); return 0; }
0.0分
0 人评分
C语言训练-斐波纳契数列 (C语言代码)浏览:2811 |
C二级辅导-计负均正 (C语言代码)浏览:647 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:762 |
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:904 |
printf基础练习2 (C语言代码)浏览:644 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:536 |
Cylinder (C语言描述,蓝桥杯)浏览:1247 |
字符逆序 (C语言代码)浏览:609 |
Hello, world! (C语言代码)浏览:714 |