1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
// http://ideone.com/8mjq2T
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <string>
struct text
{
text() = default;
text(const std::string& txt) : data(txt) {}
std::string key() const { std::string k(data); std::sort(k.begin(), k.end()); return k; }
operator std::pair<std::string, std::string>() const { return std::make_pair(key(), data); }
std::string data;
};
std::istream& operator>>(std::istream& is, text& t)
{
return is >> t.data;
}
std::ostream& operator<<(std::ostream& os, const text& t)
{
return os << t.data;
}
std::string quoted(const text& t)
{
return std::string(1, '"') + t.data + '"';
}
int main()
{
using pair_type = std::pair<std::string, std::string> ;
std::unordered_map<std::string, std::string> map =
{
pair_type(text("scooby")), pair_type(text("shaggy")), pair_type(text("veronica")),
pair_type(text("fred")), pair_type(text("daphne")), pair_type(text("wilma")),
pair_type(text("betty")), pair_type(text("barney")), pair_type(text("dino")),
pair_type(text("bambam")), pair_type(text("pebbles")), pair_type(text("george"))
};
text t;
while (std::cin >> t)
{
auto it = map.find(t.key());
if (it != map.end())
std::cout << quoted(t) << " matches " << quoted(it->second) << '\n';
else
std::cout << quoted(t) << " matches nothing\n";
}
}
|