#include <iostream>
#include <set>
#include <string>
typedef std::set<std::pair<std::string, std::string> > ssset;
ssset::iterator get_key(ssset& s, std::string key)
{
ssset::iterator it = s.lower_bound(std::make_pair(key, ""));
if (it != s.end() && it->first == key) return it;
return s.end();
}
ssset::const_iterator get_key(const ssset& s, std::string key)
{
ssset::const_iterator it = s.lower_bound(std::make_pair(key, ""));
if (it != s.end() && it->first == key) return it;
return s.end();
}
void insert(ssset& s, std::string key, std::string value)
{
s.insert(std::make_pair(key, value));
}
int main() {
ssset s;
insert(s, "abc", "def");
insert(s, "def", "def");
insert(s, "abc", "ghi");
insert(s, "abc", "ghi");
insert(s, "abc", "abc");
std::cout << "abc" << std::endl;
for (ssset::iterator it = get_key(s, "abc"); it != s.end() && it->first == "abc"; ++it)
std::cout << it->first << "->" << it->second << std::endl;
std::cout << "def" << std::endl;
for (ssset::iterator it = get_key(s, "def"); it != s.end() && it->first == "def"; ++it)
std::cout << it->first << "->" << it->second << std::endl;
std::cout << "ghi" << std::endl;
for (ssset::iterator it = get_key(s, "ghi"); it != s.end() && it->first == "ghi"; ++it)
std::cout << it->first << "->" << it->second << std::endl;
std::cout << "----- ALL ----" << std::endl;
for (ssset::iterator it = s.begin(); it != s.end(); ++it)
std::cout << it->first << "->" << it->second << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8c3RyaW5nPgoKdHlwZWRlZiAgc3RkOjpzZXQ8c3RkOjpwYWlyPHN0ZDo6c3RyaW5nLCBzdGQ6OnN0cmluZz4gPiBzc3NldDsKCnNzc2V0OjppdGVyYXRvciBnZXRfa2V5KHNzc2V0JiBzLCBzdGQ6OnN0cmluZyBrZXkpCnsKICBzc3NldDo6aXRlcmF0b3IgaXQgPSBzLmxvd2VyX2JvdW5kKHN0ZDo6bWFrZV9wYWlyKGtleSwgIiIpKTsKICBpZiAoaXQgIT0gcy5lbmQoKSAmJiBpdC0+Zmlyc3QgPT0ga2V5KSByZXR1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