#include #include #include #include // TODO: implement a dictionary that maps keys to (multiple) values class Dictionary { public: // hint: use translations.equal_range for finding all values associated with a key void add(std::string&& key, std::string&& value) { // TODO: add the value to the multimap } void remove(const std::string& key) { // TODO: remove all values associated with the key } void remove(const std::string& key, const std::string& value) { // TODO: remove the value associated with the key } // NOTE: this method is const, because it does not modify the dictionary void find(const std::string& key, std::ostream& out) const { // TODO: print all values associated with the key } // NOTE: this method is const, because it does not modify the dictionary void list(std::ostream& out) const { // TODO: print all key-value pairs in the dictionary as "key: value" } private: std::unordered_multimap translations; }; void program_loop(Dictionary& dictionary, std::istream& in, std::ostream& out) { std::string line; std::string command; // TODO: read commands from stdin: // - add : add a new key-value pair to the dictionary // - remove : remove a specific key-value pair from the dictionary // - remove : remove all key-value pairs with the given key // - find : print all values associated with the given key // - list: print all key-value pairs in the dictionary // - quit: exit the program while (std::getline(in, line)) { std::istringstream iss(std::move(line)); if (!(iss >> command)) { continue; } if (command == "add") { } else if (command == "remove") { } else if (command == "find") { } else if (command == "list") { } else if (command == "quit") { break; } else { out << "Unknown command: " << command << std::endl; } } } int main() { Dictionary dictionary; program_loop(dictionary, std::cin, std::cout); }