#include<stdio.h> #include<string.h> typedef struct { char sno[20]; char name[20]; int grade1; int grade2; int grade3; }STUDENT, * STU; int main() { int N; char name[20]; char sno[20]; scanf("%d", &N); int N_1 = N; STU s = (STU)malloc(sizeof(STUDENT) * N); STU p = s; if (p == NULL) return; while (N_1-- > 0) { scanf("%s %s %d %d %d", &sno, &name, &(p->grade1), &(p->grade2), &(p->grade3)); strcpy(&(p->name), &name); strcpy(&(p->sno), &sno); p++; } int average1=0,average2=0,average3=0; for (int i = 0; i < N; i++) { average1+=(s + i)->grade1; average2+=(s + i)->grade2; average3+=(s + i)->grade3; } printf("%d %d %d\n",average1/N,average2/N,average3/N); int max=0; for (int i = 1; i < N; i++) { if((s + max)->grade1<(s + i)->grade1){//他这有漏洞.只比较一个即可 max=i; } } printf("%s %s %d %d %d\n",(s + max)->sno,(s + max)->name,(s + max)->grade1, (s + max)->grade2,(s + max)->grade3); free(s); s = NULL; p = NULL; return 0; }
0.0分
0 人评分