Advertisement
TwITe

Untitled

Aug 28th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. struct student_result {
  2.     string first_name;
  3.     string last_name;
  4.     vector <int> marks;
  5. };
  6.  
  7. double average_mark(const vector <int>& marks) {
  8.     int sum_marks = 0;
  9.     for (auto mark : marks) {
  10.         sum_marks += mark;
  11.     }
  12.     return (sum_marks / 3.0);
  13. }
  14.  
  15. bool marks_compare(const student_result& first_student, const student_result& second_student) {
  16.     return (average_mark(first_student.marks) > average_mark(second_student.marks));
  17. }
  18.  
  19. void task5() {
  20.     int n;
  21.     cin >> n;
  22.     vector <student_result> students(n);
  23.     for (int i = 0; i < n; i++) {
  24.         student_result current_student;
  25.         string current_first_name, current_last_name;
  26.         cin >> current_first_name >> current_last_name;
  27.         current_student.first_name = current_first_name;
  28.         current_student.last_name = current_last_name;
  29.         for (int i = 0; i < 3; i++) {
  30.             int mark;
  31.             cin >> mark;
  32.             current_student.marks.push_back(mark);
  33.         }
  34.         students[i] = current_student;
  35.     }
  36.     stable_sort(students.begin(), students.end(), marks_compare);
  37.     for (auto student : students) {
  38.         cout << student.first_name << " " << student.last_name << endl;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement