Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct student_result {
- string first_name;
- string last_name;
- vector <int> marks;
- };
- double average_mark(const vector <int>& marks) {
- int sum_marks = 0;
- for (auto mark : marks) {
- sum_marks += mark;
- }
- return (sum_marks / 3.0);
- }
- bool marks_compare(const student_result& first_student, const student_result& second_student) {
- return (average_mark(first_student.marks) > average_mark(second_student.marks));
- }
- void task5() {
- int n;
- cin >> n;
- vector <student_result> students(n);
- for (int i = 0; i < n; i++) {
- student_result current_student;
- string current_first_name, current_last_name;
- cin >> current_first_name >> current_last_name;
- current_student.first_name = current_first_name;
- current_student.last_name = current_last_name;
- for (int i = 0; i < 3; i++) {
- int mark;
- cin >> mark;
- current_student.marks.push_back(mark);
- }
- students[i] = current_student;
- }
- stable_sort(students.begin(), students.end(), marks_compare);
- for (auto student : students) {
- cout << student.first_name << " " << student.last_name << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement