Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Last active August 29, 2015 13:56
Show Gist options
  • Save KT-Yeh/9172150 to your computer and use it in GitHub Desktop.
Save KT-Yeh/9172150 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct dictionary{
string Word;
int Hash;
}dic[102];
bool cmp (dictionary a, dictionary b)
{
return a.Word <= b.Word;
}
int main(){
ios::sync_with_stdio(false);
// freopen ("input.txt","rt",stdin);
int nOfdic=0,i;
string str;
for (i = 0; cin >> str && str != "XXXXXX"; ++i){
dic[i].Word = str;
dic[i].Hash = 0;
for (char c : dic[i].Word)
dic[i].Hash += (3.56*c*c*c + 2*c*c + 337);
}
nOfdic = i;
sort (dic, dic+nOfdic, cmp);
while (cin >> str && str != "XXXXXX"){
int Hash = 0;
for (char c : str)
Hash += (3.56*c*c*c + 2*c*c + 337);
bool valid=0;
for (i=0; i<nOfdic; i++){
if (Hash == dic[i].Hash){
valid = 1;
cout << dic[i].Word << endl;
}
}
if (!valid) cout << "NOT A VALID WORD" << endl;
cout << "******" << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment