fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include <list>
  4. struct Student
  5. {
  6. string lastname;
  7. int course;
  8. int mathAn;
  9. int mathAl;
  10. };
  11. void printlist(list<Student> &lst){
  12. for(list<Student>::iterator it = lst.begin(); it != lst.end(); it++)
  13. cout<< (*it).lastname<<" "<< (*it).course<<" "<<(*it).mathAn<<" "<<(*it).mathAl<<" ";
  14. cout<<endl;
  15. }
  16. bool compareLastname(const Student& a, const Student& b){
  17. return a.lastname < b.lastname;
  18. }
  19. bool compareCourse(const Student& a, const Student& b){
  20. return a.course < b.course;
  21. }
  22. bool lowMark(const Student& s){
  23. return (s.mathAn < 60 || s.mathAl < 60);
  24. }
  25. int main() {
  26. list<Student> lst;
  27. lst.push_back({"Ivanov", 1, 75, 80});
  28. lst.push_back({"Frolov", 2, 55, 70});
  29. lst.push_back({"Cheprazov", 1, 90, 95});
  30. lst.push_back({"Pinti", 2, 61, 62});
  31. lst.push_back({"Georgiev", 1, 45, 88});
  32. lst.push_back({"Bondar", 2, 78, 85});
  33. cout << "Початковий список:" << endl;
  34. printlist(lst);
  35. lst.sort(compareLastname);
  36. cout << "sort lastname" << endl;
  37. printlist(lst);
  38. lst.sort(compareCourse);
  39. cout << "sort coyrse" << endl;
  40. printlist(lst);
  41. for(list<Student>::iterator it = lst.begin(); it != lst.end(); it++){
  42. if(it->mathAn > 60 && it->mathAl > 60){
  43. it->course++;
  44. }
  45. }
  46. cout << "next course" << endl;
  47. printlist(lst);
  48. lst.remove_if(lowMark);
  49.  
  50. cout << "<60:" << endl;
  51. printlist(lst);
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Початковий список:
Ivanov 1 75 80 Frolov 2 55 70 Cheprazov 1 90 95 Pinti 2 61 62 Georgiev 1 45 88 Bondar 2 78 85 
sort lastname
Bondar 2 78 85 Cheprazov 1 90 95 Frolov 2 55 70 Georgiev 1 45 88 Ivanov 1 75 80 Pinti 2 61 62 
sort coyrse
Cheprazov 1 90 95 Georgiev 1 45 88 Ivanov 1 75 80 Bondar 2 78 85 Frolov 2 55 70 Pinti 2 61 62 
next course
Cheprazov 2 90 95 Georgiev 1 45 88 Ivanov 2 75 80 Bondar 3 78 85 Frolov 2 55 70 Pinti 3 61 62 
<60:
Cheprazov 2 90 95 Ivanov 2 75 80 Bondar 3 78 85 Pinti 3 61 62