fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. typedef struct {
  5. std::string name;
  6. std::string surname;
  7. int test;
  8. } StudentsType;
  9.  
  10.  
  11. int main () {
  12. StudentsType student[3] = {
  13. {name: "Иван", surname: "Иванов", test: 3},
  14. {name: "Петр", surname: "Петров", test: 2},
  15. {name: "Степан", surname: "Степанов", test: 4}
  16. };
  17. std::cout << "\nДо сортировки:" << std::endl;
  18. for(const auto &i:student) std::cout << i.surname << " " << i.name << " : " << i.test << std::endl;
  19. std::sort(std::begin(student),std::end(student),[&](StudentsType &one, StudentsType &two) {
  20. return one.test>two.test;
  21. });
  22. std::cout << "\nПосле сортировки:" << std::endl;
  23. for(const auto &i:student) std::cout << i.surname << " " << i.name << " : " << i.test << std::endl;
  24. return 0;
  25. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
До сортировки:
Иванов Иван : 3
Петров Петр : 2
Степанов Степан : 4

После сортировки:
Степанов Степан : 4
Иванов Иван : 3
Петров Петр : 2