#include #include #include void split (std::vector &vec, std::string str, std::string del) { auto token = str.find(del); if (token != std::string::npos) { vec.push_back(str.substr(0, token)); split(vec, str.substr(token+del.size()), del); } else { vec.push_back(str); } } class Board { public: Board(std::string repr) { std::vector lines; split(lines, repr, "\n"); for (auto line : lines) { std::vector strcells; split(strcells, line, " "); size = 0; for (auto strcell : strcells) { if (strcell.size() == 0) continue; cells.push_back(std::stoi(strcell)); state.push_back(0); size++; } } } int size; std::vector cells; std::vector state; void mark (int ex) { for (int y=0; y extract; auto token = raw.find("\n"); if (token != std::string::npos) { std::string ex = raw.substr(0, token); std::vector vec; split(vec, ex, ","); for (auto v : vec) { extract.push_back(std::stoi(v)); } raw = raw.substr(token+2); if (raw[raw.size()-1] == '\n') raw = raw.substr(0, raw.size()-1); } else return 1; std::vector boards; std::vector str_boards; split(str_boards, raw, "\n\n"); for (auto s : str_boards) { boards.emplace_back(s); } bool flag = false; std::vector filtered = boards; for (int ex : extract) { std::cout << ex << " " << filtered.size() << std::endl; std::vector next; int size = filtered.size(), seen = 0;; for (auto& board : filtered) { board.mark(ex); if (board.win() && filtered.size() != 1) { if (!flag) { std::cout << "first winner product: " << ex * board.score() << ", " << "ex: " << ex << ", score: " << board.score() << std::endl; flag = true; } } else { next.push_back(board); } } if (next.size() == 1 && next[0].win()) { int score = next[0].score(); std::cout << "last winner product: " << ex * score << ", " << "ex: " << ex << ", score: " << score << std::endl; break; } filtered = next; } return 0; }