#include #include #include using namespace std; class Team { public: string name; int points, goals; Team(string name, int points, int goals) : points(0) { this->name = name; this->points = points; this->goals = goals; } }; // returns the index of the team // if the team is not found, push back it in the vector and return last index int indexOf(vector &teams, string& name, int& goals, int& goalsReceived) { int points = 0; if (goals > goalsReceived) { points = 3; } else if (goals == goalsReceived) { points = 1; } for (unsigned int i = 0; i < teams.size(); ++i) { if (name == teams[i].name) { teams[i].goals += goals; teams[i].points += points; return i; } } teams.push_back(Team(name, points, goals)); return teams.size() - 1; } bool myComparison(Team a, Team b) { if (a.points != b.points) return (a.points > b.points); if (a.goals != b.goals) return (a.goals > b.goals); return (a.name < b.name); } int main() { vector teams; int numberOfMatches = 6; for (int match = 0; match < numberOfMatches; ++match) { string name1, name2; getline(cin, name1, ' '); getline(cin, name2, ' '); int goals1, goals2; cin >> goals1 >> goals2; cin.ignore(); indexOf(teams, name1, goals1, goals2); indexOf(teams, name2, goals2, goals1); } sort(teams.begin(), teams.end(), myComparison); for (unsigned int i = 0; i < teams.size(); ++i) { cout << teams[i].name << "\n"; } return 0; }