#include #include #include #include #include #include using namespace std; istream& operator>>(istream& in, map>& container) { auto is_comment = [](string_view s) -> bool { return s == "//" || s == "/*" || s == "#" || s == "--"; }; // --8<-- match_begin auto match_begin = [&is_comment](const string& line, string& name) -> bool { stringstream ss{ line }; string comment, cut_mark; if ( !(ss >> comment >> cut_mark >> name) ) { return false; } if ( !is_comment(comment) ) { return false; } if ( cut_mark != "--8<--" ) { return false; } return true; }; // -->8-- // --8<-- match_end auto match_end = [&is_comment](const string& line) -> bool { stringstream ss{ line }; string comment, cut_mark; if ( !(ss >> comment >> cut_mark) ) { return false; } if ( !is_comment(comment) ) { return false; } if ( cut_mark != "-->8--" ) { return false; } return true; }; // -->8-- vector chunks; for ( string line; getline(in, line); ) { string marker; if ( match_begin(line, marker) ) { chunks.emplace_back(marker); } else if ( match_end(line) ) { if ( !chunks.empty() ) { chunks.pop_back(); } } else { for ( const auto& chunk: chunks ) { container[chunk].emplace_back(line); } } } return in; } ostream& operator<<(ostream& os, const map>& container) { for ( const auto& chunk: container ) { os << "CHUNK: " << chunk.first << '\n'; auto line = begin(chunk.second); while ( line != end(chunk.second) ) { os << *line << '\n'; ++line; } os << "-------\n\n"; } return os; } int main(void) { map> container; cin >> container; cout << container; }