Advertisement
Infiniti_Inter

7 (Alisa)

Dec 19th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7.  
  8. ifstream in("input.txt");
  9. ofstream out("output.txt");
  10.  
  11.  
  12. class Student
  13. {
  14. private:
  15.     string name;
  16.     string surname;
  17.     int mark[3];
  18.  
  19.     int GetSum()
  20.     {
  21.         int result = 0;
  22.         for (int i = 0; i < 3; ++i)
  23.             result += mark[i];
  24.         return result;
  25.     }
  26. public:
  27.     Student() {}
  28.     Student(string surname, string name, int * mark)
  29.     {
  30.         this->surname = surname;
  31.         this->name = name;
  32.         for (int i = 0; i < 3; ++i)
  33.             this->mark[i] = mark[i];
  34.     }
  35.  
  36.    
  37.  
  38.     bool operator < (Student a)
  39.     //перегружаем оператор "<", чтобы можно было использовать
  40.         //встроенную сортировку sort
  41.     {
  42.         if (this->GetSum() < a.GetSum())
  43.             return true;
  44.         if (this->GetSum() == a.GetSum() && this->mark[0] < a.mark[0])
  45.             return true;
  46.         return false;
  47.     }
  48.  
  49.     void Print()
  50.     {
  51.         out << surname << " " << name << endl;
  52.         for (int i = 0; i < 3; ++i)
  53.             out << mark[i] << " ";
  54.         out << endl;
  55.     }
  56.  
  57.    
  58.  
  59. };
  60.  
  61. int main()
  62. {
  63.     int n; in >> n;//размер массива студентов
  64.     Student * a = new Student[n];
  65.     for (int i = 0; i < n; ++i)
  66.     {
  67.         string surname, name;
  68.         int mark[3];
  69.         in >> surname >> name >> mark[0] >> mark[1] >> mark[2];
  70.         a[i] = Student(surname, name, mark);
  71.     }
  72.     sort(a, a + n);//встроенная в algorithm сортировка
  73.     for (int i = 0; i < n; ++i)
  74.         a[i].Print();
  75.     /*
  76.     пример входных данных(лучше изменить)
  77.     5
  78.     Bavera Eldred 1 2 3
  79.     Ahirlene Bode 3 2 1
  80.     Neoma Boggs 3 2 1
  81.     Cong Heston 5 5 5
  82.     Mario Beane 4 3 2
  83.     */
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement