|
发表于 2023-11-11 16:19:56
|
显示全部楼层
本楼为最佳答案
 - #include <iostream>
- #include <iomanip>
- using namespace std;
- struct stud {
- int num; //学号
- char name[10]; //姓名
- int score[3]; //3门课成绩
- int sum; //总分
- };
- int main() {
- int N;
- cin >> N;
- stud students[N];
-
- for (int i = 0; i < N; i++) {
- cin >> students[ i].num >> students[ i].name >> students[ i].score[0] >> students[ i].score[1] >> students[ i].score[2];
- students[ i].sum = students[ i].score[0] + students[ i].score[1] + students[ i].score[2];
- cout << students[ i].num << " " << students[ i].name << " " << students[ i].score[0] << " " << students[ i].score[1] << " " << students[ i].score[2] << " " << students[ i].sum << endl;
- }
-
- double totalAvg = 0;
- for (int i = 0; i < N; i++) {
- totalAvg += students[ i].sum;
- }
- totalAvg /= N;
- cout << fixed << setprecision(6) << "总平均分=" << totalAvg << endl;
-
- int maxIndex = 0;
- for (int i = 1; i < N; i++) {
- if (students[ i].sum > students[maxIndex].sum) {
- maxIndex = i;
- }
- }
- cout << students[maxIndex].num << " " << students[maxIndex].name << " " << students[maxIndex].score[0] << " " << students[maxIndex].score[1] << " " << students[maxIndex].score[2] << " " << students[maxIndex].sum << endl;
-
- return 0;
- }
复制代码 |
|