#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
std::vector<std::string> loadList()
{
std::ifstream inFile ("C:/reddit/listOfWords.txt");
std::string str;
std::vector<std::string> listOfWords;
if (inFile.is_open())
{
while (!inFile.eof())
{
inFile >> str;
listOfWords.push_back(str);
}
inFile.close();
}
return listOfWords;
}
std::string decode(std::string msg, std::vector<std::string> listOfWords)
{
for (int a = 0; a < listOfWords.size(); ++a)
{
std::string tempStr = listOfWords[a];
sort(tempStr.begin(), tempStr.end());
sort(msg.begin(), msg.end());
if (msg == tempStr)
{
return listOfWords[a];
}
}
}
int main()
{
std::vector<std::string> listOfWords = loadList();
std::string msg;
std::cin >> msg;
std::string decMsg = decode(msg, listOfWords);
std::cout << "Decoded word: " << decMsg << "\n";
std::system("PAUSE");
return 0;
}