找到所有变位词
typedef std::list<std::string> List;
typedef std::map<std::string, List> Map;
Map getAnagrams(List& input)
{
Map result;
for (const auto& s : input){
auto key = s;
std::sort(key.begin(), key.end());
auto loc = result.find (key);
if (loc != result.end ()){
loc->second.push_back (s);
}else{
result.insert ({key, List{s}});
}
}
return result;
}