博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
编程珠玑--变位词集合
阅读量:4515 次
发布时间:2019-06-08

本文共 1067 字,大约阅读时间需要 3 分钟。

有一步是必须处理的,就是对字符串进行排序;

第二步的方法就比较多:(1)采用字符串哈希(求值)(2)排序后转化为24位的位向量(3)直接排序后的字符串作为标识(书上的方法)

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 8 using namespace std; 9 10 11 int main()12 {13 ifstream dic("in.txt");14 vector
> words_pair;15 string word, word_sign;16 while(dic >> word) {17 word_sign = word;18 sort(word_sign.begin(), word_sign.end());19 words_pair.push_back(pair
(word_sign, word));20 }21 22 sort(words_pair.begin(), words_pair.end());23 vector
>::const_iterator iter;24 string pre = "";25 for (iter = words_pair.begin(); iter != words_pair.end(); iter++){26 if (pre != "" && (*iter).first != pre) {27 cout << endl;28 }29 cout << (*iter).second << " ";30 pre = (*iter).first;31 }32 33 cout << endl;34 return 0;35 }
hairedhardier harriedtrihedrahardwireairshed dashier hardies shadierairsheds radisheshardiestravisheddishware rawhideshayridesairthedrawhidehayride hydriae

以上是in.txt的内容

转载于:https://www.cnblogs.com/cane/p/3779521.html

你可能感兴趣的文章
Ubuntu/CentOS下使用脚本自动安装 Docker
查看>>
源码解读Mybatis List列表In查询实现的注意事项
查看>>
POJ 2311 Cutting Game(二维SG+Multi-Nim)
查看>>
小强的HTML5移动开发之路(16)——神奇的拖放功能
查看>>
zookeeper FastLeaderElection
查看>>
进度条
查看>>
用户画像
查看>>
HTTP报文(面试会问开发时常用的报文头格式)
查看>>
机器学习从业人员到底做什么?
查看>>
word发表博客的方法
查看>>
Programming Erlang_CHAPTER2_Basic Erlang 学习笔记(2)。
查看>>
Linux基础
查看>>
【模板】高精度
查看>>
弱弱的玩下Javascript
查看>>
二叉树相关操作
查看>>
在webstorm开发微信小程序之使用阿里自定义字体图标
查看>>
序列化模块/模块/包
查看>>
eclipse maven plugin 插件 安装 和 配置
查看>>
收集一些复杂有用的正则表达式
查看>>
子数组求和之大数溢出
查看>>