Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- class Student
- {
- private:
- string name;
- string surname;
- int mark[3];
- int GetSum()
- {
- int result = 0;
- for (int i = 0; i < 3; ++i)
- result += mark[i];
- return result;
- }
- public:
- Student() {}
- Student(string surname, string name, int * mark)
- {
- this->surname = surname;
- this->name = name;
- for (int i = 0; i < 3; ++i)
- this->mark[i] = mark[i];
- }
- bool operator < (Student a)
- //перегружаем оператор "<", чтобы можно было использовать
- //встроенную сортировку sort
- {
- if (this->GetSum() < a.GetSum())
- return true;
- if (this->GetSum() == a.GetSum() && this->mark[0] < a.mark[0])
- return true;
- return false;
- }
- void Print()
- {
- out << surname << " " << name << endl;
- for (int i = 0; i < 3; ++i)
- out << mark[i] << " ";
- out << endl;
- }
- };
- int main()
- {
- int n; in >> n;//размер массива студентов
- Student * a = new Student[n];
- for (int i = 0; i < n; ++i)
- {
- string surname, name;
- int mark[3];
- in >> surname >> name >> mark[0] >> mark[1] >> mark[2];
- a[i] = Student(surname, name, mark);
- }
- sort(a, a + n);//встроенная в algorithm сортировка
- for (int i = 0; i < n; ++i)
- a[i].Print();
- /*
- пример входных данных(лучше изменить)
- 5
- Bavera Eldred 1 2 3
- Ahirlene Bode 3 2 1
- Neoma Boggs 3 2 1
- Cong Heston 5 5 5
- Mario Beane 4 3 2
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement