Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <string>
- #include <cmath>
- #include <algorithm>
- struct Student
- {
- string F, I;
- int score[3];
- int fullScore()
- {
- return score[0] + score[1] + score[2];
- }
- double averageGeom()
- {
- return sqrt(score[0] * score[1] * score[2]);
- }
- bool pred(const Student& stud)
- {
- if (fullScore() < stud.fullScore()) return true;
- else if (fullScore() == stud.fullScore() && averageGeom() < stud.averageGeom()) return true;
- else if (averageGeom() == stud.averageGeom()) return false;
- }
- };
- vector<Student> initVector(ifstream& in)
- {
- vector<Student> base;
- while (in.peek() != EOF)
- {
- Student stud;
- in >> stud.F >> stud.I;
- for (int i = 0; i < 3; ++i) in >> stud.score[i];
- base.push_back(stud);
- }
- return base;
- }
- void printVector(vector<Student> base, ofstream& out)
- {
- for (Student stud : base)
- {
- out << stud.F << " " << stud.I << " ";
- for (int i = 0; i < 3; ++i) out << elem.score[i];
- }
- }
- int main()
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- vector<Student> base = initVector(in);
- sort(base.begin(), base.end(), pred);
- printVector(base, out);
- }
- input.txt:
- sidorov sergey 100 100 100
- kuzichkin pavel 50 50 50
- orlov daniil 90 90 90
- imanov rauf 100 100 100
- tihonov levan 84 87 99
- output.txt:
- kuzichkin pavel 50 50 50
- tihonov levan 84 87 99
- orlov daniil 90 90 90
- imanov rauf 100 100 100
- sidorov sergey 100 100 100
Add Comment
Please, Sign In to add comment