|
发表于 2023-11-11 16:15:43
|
显示全部楼层
本楼为最佳答案
- #include <iostream>
- #include <string>
- using namespace std;
- struct Student
- {
- char num[11]; //学号,最多10个字符
- char name[11]; //姓名, 最多10个字符
- int s1, s2, s3; //三门课的考试成绩
- int total; //总成绩
- };
- int main()
- {
- int n;
- cin >> n;
- Student stu[n];
- for (int i = 0; i < n; i++)
- {
- cin >> stu[ i].num >> stu[ i].name >> stu[ i].s1 >> stu[ i].s2 >> stu[ i].s3;
- stu[ i].total = stu[ i].s1 + stu[ i].s2 + stu[ i].s3;
- }
- int maxTotal = -1;
- for (int i = 0; i < n; i++)
- {
- if (stu[ i].total > maxTotal)
- {
- maxTotal = stu[ i].total;
- }
- }
- for (int i = 0; i < n; i++)
- {
- if (stu[ i].total == maxTotal)
- {
- cout << stu[ i].num << " " << stu[ i].name << " " << stu[ i].total << endl;
- }
- }
- return 0;
- }
复制代码 |
|