鱼C论坛

 找回密码
 立即注册
查看: 1870|回复: 1

[已解决]求助一下

[复制链接]
发表于 2023-11-11 16:19:56 | 显示全部楼层    本楼为最佳答案   
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;

  4. struct stud {
  5.     int num; //学号
  6.     char name[10]; //姓名
  7.     int score[3]; //3门课成绩
  8.     int sum; //总分
  9. };

  10. int main() {
  11.     int N;
  12.     cin >> N;
  13.     stud students[N];
  14.    
  15.     for (int i = 0; i < N; i++) {
  16.         cin >> students[ i].num >> students[ i].name >> students[ i].score[0] >> students[ i].score[1] >> students[ i].score[2];
  17.         students[ i].sum = students[ i].score[0] + students[ i].score[1] + students[ i].score[2];
  18.         cout << students[ i].num << " " << students[ i].name << " " << students[ i].score[0] << " " << students[ i].score[1] << " " << students[ i].score[2] << " " << students[ i].sum << endl;
  19.     }
  20.    
  21.     double totalAvg = 0;
  22.     for (int i = 0; i < N; i++) {
  23.         totalAvg += students[ i].sum;
  24.     }
  25.     totalAvg /= N;
  26.     cout << fixed << setprecision(6) << "总平均分=" << totalAvg << endl;
  27.    
  28.     int maxIndex = 0;
  29.     for (int i = 1; i < N; i++) {
  30.         if (students[ i].sum > students[maxIndex].sum) {
  31.             maxIndex = i;
  32.         }
  33.     }
  34.     cout << students[maxIndex].num << " " << students[maxIndex].name << " " << students[maxIndex].score[0] << " " << students[maxIndex].score[1] << " " << students[maxIndex].score[2] << " " << students[maxIndex].sum << endl;
  35.    
  36.     return 0;
  37. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-7 05:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表