#include "iostream"\n#include "string"\n\nusing namespace std;\n\n// 定义学生结构体\nstruct Student {\n string name;\n int math;\n int chinese;\n int english;\n int geography;\n int total;\n};\n\n// 选择排序算法\nvoid selectionSort(Student students[], int n) {\n for (int i = 0; i < n - 1; i++) {\n int maxIndex = i;\n for (int j = i + 1; j < n; j++) {\n if (students[j].total > students[maxIndex].total) {\n maxIndex = j;\n }\n }\n // 交换位置\n if (maxIndex != i) {\n swap(students[i], students[maxIndex]);\n }\n }\n}\n\nint main() {\n int N;\n cin >> N;\n Student students[N];\n\n // 输入每个学生的信息\n for (int i = 0; i < N; i++) {\n cin >> students[i].name >> students[i].math >> students[i].chinese >> students[i].english >> students[i].geography;\n students[i].total = students[i].math + students[i].chinese + students[i].english + students[i].geography;\n }\n\n selectionSort(students, N);\n\n // 输出每位同学的总分\n for (int i = 0; i < N; i++) {\n cout << students[i].total << endl;\n }\n\n // 输出总分最高的同学姓名\n cout << students[0].name << endl;\n\n // 找出所有成绩中最高的分数和最小的分数\n int maxScore = students[0].total;\n int minScore = students[N - 1].total;\n cout << maxScore << " " << minScore << endl;\n\n return 0;\n}


原文地址: https://www.cveoy.top/t/topic/pEPY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录