This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

reddit

By: a guest on Oct 21st, 2012  |  syntax: C++  |  size: 0.97 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data