Skip to content

Instantly share code, notes, and snippets.

@yamaguchi1024
Created May 29, 2017 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamaguchi1024/58f79f6744ab22259e344366149abc1e to your computer and use it in GitHub Desktop.
Save yamaguchi1024/58f79f6744ab22259e344366149abc1e to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<string, string> P;
int main() {
map<string, string> dic;
// Make dictionary
string line;
ifstream dict ("/usr/share/dict/american-english");
if (dict.is_open())
{
while ( getline (dict,line) )
{
if(line.length() > 16)
continue;
if(line.find("'") != string::npos)
continue;
string val = line;
sort(line.begin(), line.end());
dic.insert(P(line, val));
}
dict.close();
}
// Compare user input and dictionary
for(;;) {
cout << ">> ";
string input;
cin >> input;
auto res = dic.find(input);
if ( res != dic.end() )
cout << res->second << endl;
else
cout << "not found..." << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment