Advertisement
ToastyStoemp

Untitled

Sep 14th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. std::cout << "----- Anagram List -----" << std::endl << std::endl;
  2.     VStr anagramWords;
  3.     MStr sortedWords;
  4.  
  5.     //creation of the multimap with sorted words, will be used to check for the existance of anagrams
  6.     for (VStr::iterator it = alphaWords.begin(); it != alphaWords.end(); ++it)
  7.     {
  8.         std::string value = *it;
  9.         std::string key = WordSort(value);
  10.         sortedWords.insert ( std::pair<std::string, std::string>(key, value));
  11.     }
  12.  
  13.     //checking for anagrams
  14.     for (VStr::iterator it = alphaWords.begin(); it != alphaWords.end(); ++it)
  15.     {
  16.         std::string searchFor = *it;
  17.         searchFor = WordSort(searchFor);
  18.         if (sortedWords.count(searchFor) > 1)
  19.         {
  20.             std::pair <std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> ref;
  21.             ref = sortedWords.equal_range(searchFor);
  22.             for (MStr::iterator tick = ref.first; tick != ref.second; ++tick)
  23.             {
  24.                 std::cout << ' ' << tick->second << std::endl;
  25.             }
  26.             MStr::iterator id = sortedWords.find(searchFor);
  27.             std::cout << "\n";
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement