#include #include #include #include #include #include #include #include #include #include #include std::map> read_table(std::istream& is) { std::map> result { }; std::string line; while (std::getline(is, line)) { std::istringstream iss { line }; std::string entry { }; std::string tag { }; std::set tags { }; iss >> entry; while (iss >> tag) tags.insert(tag); result[entry] = tags; } return result; } int main(int argc, char* argv[]) { if (argc <= 2) { std::cerr << "Usage: " << argv[0] << " FILE [TAGS...]" << std::endl; return 1; } std::ifstream ifs { argv[1] }; std::set tags { &argv[2], &argv[argc] }; auto table = read_table(ifs); auto contains = [&tags](auto pair) { return std::includes(pair.second, tags); }; auto get_entry = [](auto pair) { return pair.first; }; std::ranges::copy(table | std::views::filter(contains) | std::views::transform(get_entry), std::ostream_iterator{std::cout, "\n"}); }