解题思路:
封装函数 调用
注意事项:

参考代码:

//
// Created by Freedom on 2024/3/19.
//
#include <iostream>
#include <cstdio>

using namespace std;
struct Student {
   string num, name;
   double class1, class2, class3, total;
   Student* next;
};

void InsertSTU(Student* s, string num, string name, double class1, double class2, double class3) {
   Student* insert = (Student*) ::malloc(sizeof(Student));
   Student* s2 = s;
   while (s2->next)
       s2 = s2->next;
   s2->next = insert;
   insert->num = num;
   insert->name = name;
   insert->class1 = class1;
   insert->class2 = class2;
   insert->class3 = class3;
   insert->total = insert->class1 + insert->class2 + insert->class3;
   insert->next = NULL;
}

void FindAverage(Student* s,double &first,double &second,double &third,int n){
   Student* replace = s;
   while (replace){
       first += replace->class1;
       second += replace->class2;
       third += replace->class3;
       replace = replace->next;
   }
   first /= n;
   second /= n;
   third /= n;
}

Student* FindMax(Student* s){
   Student* replace = s,*max = s;
   while (replace){
       if(max->total < replace ->total)
           max = replace;
       replace = replace ->next;
   }
   return max;
}

int main() {
   int n;
   double avg_class1 = 0,avg_class2 = 0,avg_class3 = 0;
   cin >> n;
   Student student;
   Student head;
   cin >> head.num >> head.name >> head.class1 >> head.class2 >> head.class3;
   head.next = NULL;
   head.total = head.class1 + head.class2 + head.class3;

   for (int i = 1; i < n; ++i) {
       cin >> student.num >> student.name >> student.class1 >> student.class2 >> student.class3;
       InsertSTU(&head,student.num,student.name,student.class1,student.class2,student.class3);
   }
   FindAverage(&head,avg_class1,avg_class2,avg_class3,n);
   Student* max = FindMax(&head);
   ::printf("%.0f %.0f %.0f\n",avg_class1,avg_class2,avg_class3);
   cout << max->num << " " << max->name << " " << max->class1 << " " << max->class2 << " " << max->class3 << endl;
   return 0;
}


点赞(0)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论