首页 > 其他 > 详细

找到所有变位词

时间:2016-01-23 07:54:24      阅读:197      评论:0      收藏:0      [点我收藏+]
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;
}

 

找到所有变位词

原文:http://www.cnblogs.com/wuOverflow/p/5152749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!