Beispiel #1
0
void readWords(const LetterMap &letterMap, WordMap &words)
{
  ifstream inf("words.txt");
  string word, sortedWord;
  short value;

  while( getline(inf, word))
  {
    if(word.length() <= MAX_WORD_LENGTH
       && word.find_first_not_of("abcedefghijklmnopqrstuvwxyz") == string::npos)
    {
      value = 0;

      for(string::const_iterator itr = word.begin(); itr != word.end(); itr++)
        value += (letterMap.find(*itr))->second;

      words.insert(WordMap::value_type(word, value));
    } // if word up to MAX_WORD_LENGTH characters and no captial letters.
  } // while
}  // readWords()
Beispiel #2
0
void processBlankWord(const WordMap &words, string &originalWord,
                      set<string> &bestWords, short &bestCount,
                      const LetterMap &letterMap,  
                      WordMap::const_iterator &itr,
                      char letter)
{
  int count = itr->second;

  if(std::count(itr->first.begin(), itr->first.end(),
     letter) > std::count(originalWord.begin(), originalWord.end(),
     letter)) // space used
     count -= letterMap.find(letter)->second;

  if(count >= bestCount)
  {
    if(count > bestCount)
    {
      bestWords.clear();
      bestCount = count;
    } // if better than those previous

    bestWords.insert(itr->first);
  } // if at least as good as previous
} // processBlankWord()