C++ 编程练习:计算学生总分、找出最高分和最低分
#include
struct Student { string name; int math; int chinese; int english; int geography; int total; };
bool compare(Student s1, Student s2) { return s1.total > s2.total; }
int main() {
int N;
cin >> N;
vector
sort(students.begin(), students.end(), compare);
for (int i = 0; i < N; i++) {
cout << students[i].total << endl;
}
cout << students[0].name << endl;
int highest = max({students[0].math, students[0].chinese, students[0].english, students[0].geography});
int lowest = min({students[0].math, students[0].chinese, students[0].english, students[0].geography});
cout << highest << " " << lowest << endl;
return 0;
}
原文地址: http://www.cveoy.top/t/topic/pFsW 著作权归作者所有。请勿转载和采集!