fork download
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <limits>
  5. #include <string>
  6. #include <vector>
  7.  
  8. struct student
  9. {
  10. student(const std::string& name, const int year, const double average)
  11. : name(name), year(year), average(average) {}
  12.  
  13. std::string name;
  14. int year;
  15. double average;
  16. };
  17.  
  18. int main()
  19. {
  20. std::vector<student> students;
  21. students.push_back(student("Vasya", 1992, 4.5));
  22. students.push_back(student("Marina", 1993, 5.0));
  23. students.push_back(student("Olya", 1994, 4.9));
  24.  
  25. std::sort(
  26. students.begin()
  27. , students.end()
  28. , [](const student& left, const student& right)
  29. {
  30. return left.average < right.average;
  31. });
  32.  
  33. for (const student& stud : students)
  34. {
  35. std::cout << stud.name << '\n';
  36. }
  37. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Vasya
Olya
Marina