#include #include #include #include #include #include #include #include "oop_algos.hpp" #include "venues.hpp" using std::cin; using std::cout; using std::endl; using std::ostream; using std::string; using std::vector; using std::unordered_map; using std::pair; using cs427_527::VenueHistory; using cs427_527::TeamVenues; namespace std { ostream& operator<<(ostream& os, const pair& p); } int main(int argc, char **argv) { VenueHistory history; string line; while (std::getline(cin, line)) { // split line into vector containing fields vector fields; cs427_527::split(line.begin(), line.end(), std::back_inserter(fields), '|', [](auto& s, const auto& elt) { s += elt; }, string{}); // make sure everything was read correctly if (fields.size() == 8) { history.addGame(fields[2], fields[4], fields[7]); } } vector< pair< string, string > > home_venues; // for each entry in the map through map for (auto& entry : history) { auto& team = entry.first; auto& venues = entry.second; // for each venue that a team played in 3 or more times... for (auto& venue : venues) { vector games = venues.games(venue); if (games.size() >= 3 && (size_t)(games[games.size() - 1] - games[0]) > games.size()) { home_venues.push_back(std::make_pair(team, venue)); } } } std::sort(home_venues.begin(), home_venues.end(), [&](auto& p1, auto& p2) { return p1.first < p2.first; }); std::copy(home_venues.begin(), home_venues.end(), std::ostream_iterator& >{cout, "\n"}); return 0; } namespace std { ostream& operator<<(ostream& os, const pair& p) { os << p.first << "|" << p.second; return os; } }