#include #include #include #include #include #include #include #include #include #include #include #include #define pb push_back #define mp make_pair #define f first #define s second #define ll long long using namespace std; class Game { map scores; map take; map give; public: struct Team { int take, give; int points; string name; Team(string _name, int _p, int _t, int _g) { name = _name; points = _p; take = _t; give = _g; } bool operator < (const Team &other) const { if (points == other.points) { if (give == other.give) { return name < other.name; } return give < other.give; } return points < other.points; } }; Game() { scores.clear(); take.clear(); give.clear(); } void add(string team1, string team2, int score1, int score2) { if (scores.find(team1) == scores.end()) { scores[team1] = 0; } if (scores.find(team2) == scores.end()) { scores[team2] = 0; } if (score1 > score2) { scores[team1] += 3; } else if (score2 > score1) { scores[team2] += 3; } else { scores[team1] += 1; scores[team2] += 1; } take[team2] += score1; take[team1] += score2; give[team1] += score1; give[team2] += score2; } vector flush_scores() { vector allTeams; for (const auto &it: scores) { allTeams.push_back(Team(it.first, it.second, take[it.first], give[it.first])); } sort(allTeams.begin(), allTeams.end()); vector names; for (const auto &it: allTeams) { names.push_back(it.name); } return names; } }; int main() { #ifndef ONLINE_JUDGE ifstream cin("test.in"); ofstream cout("test.out"); #endif string t1, t2; int s1, s2; Game game; while(cin >> t1 >> t2 >> s1 >> s2) game.add(t1, t2, s1, s2); vector results = game.flush_scores(); reverse(results.begin(), results.end()); for (const auto &it: results) { cout << it << "\n"; } return 0; }