Advertisement
myname0

практика_сортировка_5

Jul 3rd, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7. struct Person
  8. {
  9.         string name;
  10.         string secondname;
  11.         string surname;
  12.         int year;
  13.         int marks [5];
  14. };
  15.  
  16. ifstream in("input.txt");
  17. ofstream out ("output.txt");
  18. bool fun (Person &x, Person &y )
  19. {
  20.  
  21.     if (x.surname == y.surname)
  22.         return x.year > y.year;
  23.     else return x.surname < y.surname;
  24. }
  25. void print(Person &x)
  26. {
  27.     out << x.surname << " " << x.name << " " << x.secondname << " " << x.year << " ";
  28.     for(int i = 0; i < 5; i++)
  29.         out << x.marks[i] << " ";
  30.     out << endl;
  31. }
  32.  
  33. int main()
  34.  
  35. {
  36.        
  37.        
  38.         vector <Person> vec;
  39.         Person List;
  40.         int n;
  41.         in >> n;
  42.         for(int i = 0; i < n; i++)
  43.         {
  44.                 in >> List.surname;
  45.                 in >> List.name;
  46.                 in >> List.secondname;
  47.                 in >> List.year;
  48.                 for(int i = 0; i < 5; i++)
  49.                     in >> List.marks[i];
  50.                 vec.push_back(List);
  51.         }
  52.         sort(vec.begin(), vec.end(), fun);
  53.         for_each(vec.begin(), vec.end(), print);
  54.    
  55.  
  56.         return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement