map练习-Lexicon词典-anagram游戏
来源:互联网 发布:广州蓝盾怎么样 知乎 编辑:程序博客网 时间:2024/06/06 17:19
static string character_sort(string str){ for(int i = 0; i < str.size()-1; i++){ int j = i; int key = str[i+1]; while(str[j] > key && j >= 0){ str[j+1] = str[j]; j--; } str[j+1] = key; } return str;}void complie_map(map<string, vector<string>>& anagrams){ Lexicon english("EnglishWords.dat"); for(auto word : english){ string key = character_sort(word); if( anagrams.find(key) != anagrams.end() ) anagrams[key].push_back(word); else{ vector<string> v; v.push_back(word); anagrams.insert( pair<string, vector<string>> (key, v) ); } }}void test(){ map<string, vector<string>> anagrams; complie_map(anagrams); string str; cout<<"input your string:"; cin>>str; cout<<str<<"'s anagrams are:"<<endl; string key = character_sort(str); //注意!!!key值并不一定是English word map<string, vector<string>>::iterator it = anagrams.find(key); if( it != anagrams.end() ){ for(int i = 0; i < it->second.size(); i++) cout<<it->second[i]<<endl; } cout<<"the size of the EnglishWords map is:"<<anagrams.size()<<endl;}int main() { while(true){ string str; test(); cout<<"Continue?"; cin>>str; if(str == "no") break; } return 0;}
0 0
- map练习-Lexicon词典-anagram游戏
- bzoj1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典
- 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
- 【BZOJ1633】[Usaco2007 Feb]The Cow Lexicon 牛的词典【DP】
- BZOJ1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 DP
- BZOJ1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
- BZOJ 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
- use map to build a lexicon
- ACM练习 题目1029:魔咒词典 C++ map的使用
- leetcode 242. Valid Anagram | Map
- LeetCode 242. Valid Anagram (map使用)
- |BZOJ 1633|字符串DP|[Usaco2007 Feb]The Cow Lexicon 牛的词典
- 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典(DP)
- Map练习!!!
- Map练习
- Map练习
- anagram
- Anagram
- C - The C Answer (2nd Edition) - Exercise 1-3
- 从源码看Spring bean 生命周期
- [MarsZ]程序猿谈大学之工作三年半的程序猿给大学童鞋的一些注释
- 在Ubuntu14.04上使用devstack安装OpenStack
- pow(x,y)函数的用法及实现算法
- map练习-Lexicon词典-anagram游戏
- LeetCode#5 Longest Palindromic Substring
- Error: “app_name” is not translated in af
- maven使用
- STM32学习笔记系列
- android中夸进程通讯的四中方法
- 网络-WinSocket-socket编程
- 三期_day09_信息+订单管理_II
- nodejs - 升级