Beispiel #1
0
int main(int argc, char **argv)
{
  //This is the group of letters that must be present in the word
	const char *required = "ak";
  
  //Group of available letters (note that 'required' is a subset of available letters)
	const char *available = "akdid";
  

	const char *file = "Dictionary.txt";
	int count = GetNumEntriesInFile(file);
	char **words = ReadWords(file, count);
	
  std::cout << count <<"\n";

  //Walk the list of words and remove any word that doesn't contain all required letters or words that contain letters not in the available group.
  for (int x = 0; x < count; x++)
	{
		if (AllLettersInSet(required, words[x]) && AllLettersInSet(words[x], available))
		{
			// keep this word
		}
		else
    {
			delete [] words[x];
			words[x] = 0;
		}
	}
  
  
	//All surviving words satify the query and should be reported
	for (int x = 0; x < count; x++)
	{
		if (words[x] != 0)
			printf("%lu %s\n", strlen(words[x]), words[x]);
	}
	
	return 0;
}
//Print all words that satisfy the condition: All characters in required must be in word and all letters in word must be in available
//The words are printed in order of length from longest to shortest.
void BearHelper::GetAllWords(const char* required, const char* available)
{
    ExpandableArray a = ExpandableArray(size);
    //Go in order through the dictionary.
    for (int i = 0; i < sizeof(theDictionary); i++)
    {
        if (AllLettersInSet(required, theDictionary))
        {
            a.Append(theDictionary);
        }
    }
    a.Sort();
    for (int i = 0; i < size; i++)
    {
        printf(a.get(i));
    }
    //Check if each word matches.

    //If it does, add it to the expandable set.

    //Sort the expandable set.

    //Print the expandable set.
}