Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::cout << "----- Anagram List -----" << std::endl << std::endl;
- VStr anagramWords;
- MStr sortedWords;
- //creation of the multimap with sorted words, will be used to check for the existance of anagrams
- for (VStr::iterator it = alphaWords.begin(); it != alphaWords.end(); ++it)
- {
- std::string value = *it;
- std::string key = WordSort(value);
- sortedWords.insert ( std::pair<std::string, std::string>(key, value));
- }
- //checking for anagrams
- for (VStr::iterator it = alphaWords.begin(); it != alphaWords.end(); ++it)
- {
- std::string searchFor = *it;
- searchFor = WordSort(searchFor);
- if (sortedWords.count(searchFor) > 1)
- {
- std::pair <std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> ref;
- ref = sortedWords.equal_range(searchFor);
- for (MStr::iterator tick = ref.first; tick != ref.second; ++tick)
- {
- std::cout << ' ' << tick->second << std::endl;
- }
- MStr::iterator id = sortedWords.find(searchFor);
- std::cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement