1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
int main()
{
vector<string> dict, inputWords, final;
vector<string>::iterator dIt, fIt;
ifstream ins;
int i, n, j, k;
string word, temp, sortWord;
inputs(word, inputWords, dict, ins); //asks user for puzzle words, sorts each one, adds
//them to vector inputWords; loads all words from
//dictionary file into vector dict
for(i=0;i<(inputWords.size());i++) //for each puzzle word
{
k=(inputWords[i]).length();
for(n=3;n<=k;n++) //dictionary words are at least 3 letters long
{
word.clear();
temp=(inputWords[i]);
for(j=0;j<n;j++)
{
word.push_back(temp[j]);
}
do
{
do
{
searchDict(dict, final, word, dIt, fIt, sortWord); //checks vector dict for
//current permutation of word; if
//found, adds to vector final;
//sortWord is last word added
}while(next_permutation(word.begin(),word.end()));
}while(next_combination((inputWords[i]).begin(), (inputWords[i]).end(),
word.begin(), word.end()));
sortVec(final, sortWord); //***see below***
}
printVector(final); //prints final vector
final.clear();
}
system("pause");
return 0;
}
void sortVec(vector<string>& vec, string key)
{
if(key!="")
{
vector<string>::iterator temp=find(vec.begin(), vec.end(), key);
sort(temp, vec.end());
}
}
|