1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <fstream>
  6.  
  7.  
  8. std::vector<std::string> loadList()
  9. {
  10.     std::ifstream inFile ("C:/reddit/listOfWords.txt");
  11.     std::string str;
  12.  
  13.     std::vector<std::string> listOfWords;
  14.    
  15.     if (inFile.is_open())
  16.     {
  17.         while (!inFile.eof())
  18.         {
  19.             inFile >> str;
  20.             listOfWords.push_back(str);
  21.         }
  22.         inFile.close();
  23.     }
  24.  
  25.     return listOfWords;
  26. }
  27.  
  28. std::string decode(std::string msg, std::vector<std::string> listOfWords)
  29. {
  30.     for (int a = 0; a < listOfWords.size(); ++a)
  31.     {
  32.         std::string tempStr = listOfWords[a];
  33.         sort(tempStr.begin(), tempStr.end());
  34.         sort(msg.begin(), msg.end());
  35.        
  36.         if (msg == tempStr)
  37.         {
  38.             return listOfWords[a];
  39.         }
  40.     }
  41. }
  42.  
  43. int main()
  44. {
  45.     std::vector<std::string> listOfWords = loadList();
  46.     std::string msg;
  47.         std::cin >> msg;
  48.     std::string decMsg = decode(msg, listOfWords);
  49.     std::cout << "Decoded word: " << decMsg << "\n";
  50.     std::system("PAUSE");
  51.     return 0;
  52. }