|
Due 11pm, Monday, April 11th (75 points)
Goals
Sample expanded output (input from kids.dict)
The longest word found is 7 characters
with one reduction like this ...
p l a n e t s
p l a n t s
p a n t s
p a n t
a n t
a t
a
|
Sample end of output
charms --> harms charm hearts --> heart paints --> pants paint planet --> plant plane plants --> pants plant trains --> rains train 6 words of length 6 planets --> plants planet 1 words of length 7 0 words of length 8 |
Overview
We define word reduction as removing a single letter from a word while
leaving the remaining letters in their original order so that the
resulting sequence of characters is also a word.
A good word can be reduced step-by-step until all that is
left is a or i.
Your program will answer the question:
what is the biggest word in the given dictionary that
can be reduced?
Your task is to print all the good words from the provided dictionaries. Each good word of size n should be printed with the smaller word(s) of size n-1 that it reduces to.
Specification
There are four dictionaries named kids.dict, kidsplus.dict, huge.dict, and
yawl.dict in the ~katz362/support/dict directory.
The huge one is 1.8 MB and the yawl one (yet another word list) is 2.7 MB, so you probably want to link to them.
These are merely lists of words one per line.
You should read the words as strings from standard input.
The one-letter words a and i are the only good one-letter words. They are not in the provided dictionaries. For each good word of length n > 1, print the word and print all of the good words of length n-1 that are the next step in their reduction. Print how many words are in each set of good words of length n. Your output of those words does not need to match the example in format or order.
In addition, after printing the word lists, the program should show the step-by-step reduction of one of the longest words in inverted pyramid form as shown above. If there is only one longest word, print its reduction. If there are multiple longest words, choose one and print its reduction. Whenever you have a choice of multiple words of equal length, choose one.
You must use the hash set container class as well as vector. You do not need to use iterators although you may. The entire program should be in one file.
Your program should be efficient, well-structured, use C++ appropriately, and use data structures appropriately.
Submit only your single file program (ending in .cpp) as the words assignment.
Helpful Hints
Use the substring operation on strings to remove a letter.
If s is a string, s.substr(0, i) will return the first i characters.
s.substr(j) will return the characters from index j to the end of the string.
String indexes start at 0.
As you read words from the dictionary, check whether they contain an a or i. If not, do not store them anywhere in your program.
Store the words in lists (vectors, linked lists) in which all the words in a list are the same length. Call those original words.
After reading all the original words into lists, go through each list and build hash sets of good words. If an original word of length n can be reduced to a good word of length n-1 by removing one letter, add it to the set of good words of length n.
Use a typedef to give a handy name to your hash set type. Use the examples as a guide.