fork download
  1. #include <iostream>
  2. #include <list>
  3. using namespace std;
  4.  
  5. struct Student{
  6. string lastName;
  7. int year;
  8. int matan;
  9. int linal;
  10. };
  11. bool compareByLastName(const Student &student1, const Student &student2){
  12. return (student1.lastName)<(student2.lastName);
  13. }
  14. bool compareByYear(const Student &student1, const Student &student2){
  15. return (student1.year)<(student2.year);
  16. }
  17. bool removeIfComparator(const Student &student1){
  18. return ((student1.matan)<60) or ((student1.linal<60));
  19. }
  20.  
  21. void printList(list<Student> &lst){
  22. for(list<Student>::iterator it = lst.begin();it!=lst.end();it++){
  23. cout<<(*it).lastName<<" "<<(*it).year<<" "<<(*it).matan<<" "<<(*it).linal<<endl;
  24. }
  25. }
  26.  
  27. int main(){
  28. Student firstStudent;
  29. list<Student> lst;
  30. for(int i=0;i<3;i++){
  31. cin>>firstStudent.lastName>>firstStudent.year>>firstStudent.matan>>firstStudent.linal;
  32. lst.push_back(firstStudent);
  33. }
  34. printList(lst);
  35. lst.sort(compareByLastName);
  36. cout<<"Sorted by last name list: ";
  37. printList(lst);
  38. lst.sort(compareByYear);
  39. cout<<"Sorted by year list: ";
  40. printList(lst);
  41. for(list<Student>::iterator it=lst.begin();it!=lst.end();it++){
  42. if((*it).matan>60 && (*it).linal>60){
  43. (*it).year++;
  44. }
  45. }
  46. lst.remove_if(removeIfComparator);
  47. cout<<"Updated list after exams: ";
  48. printList(lst);
  49. }
Success #stdin #stdout 0s 5320KB
stdin
Georgiyev 1 100 100 Pupkin 3 54 32 Semechkin 2 80 95
stdout
Georgiyev 1 100 100
Pupkin 3 54 32
Semechkin 2 80 95
Sorted by last name list: Georgiyev 1 100 100
Pupkin 3 54 32
Semechkin 2 80 95
Sorted by year list: Georgiyev 1 100 100
Semechkin 2 80 95
Pupkin 3 54 32
Updated list after exams: Georgiyev 2 100 100
Semechkin 3 80 95