Some word games require the player to find words that can be formed using the letters of another word. For example, given the word SWIMMING then other words that can be formed using the letters include SWIM, WIN, WING, SING, MIMING, etc. Write a c++ program that lets the user enter a word and then output all the words contained in the file words.txt (included on the website with this book) that can be formed from the letters of the entered word. One algorithm to do this is to compare the letter histograms for each word. Create an array that counts up the number of each letter in the entered word (e.g., one S, one W, two I, two M, etc.) and then creates a similar array for the current word read from the file. The two arrays can be compared to see if the word from the file could be created out of the letters from the entered word.
Some word games require the player to find words that can be formed using the
letters of another word. For example, given the word SWIMMING then other
words that can be formed using the letters include SWIM, WIN, WING, SING,
MIMING, etc. Write a c++ program that lets the user enter a word and then output
all the words contained in the file words.txt (included on the website with this
book) that can be formed from the letters of the entered word. One
to do this is to compare the letter histograms for each word. Create an array that
counts up the number of each letter in the entered word (e.g., one S, one W, two
I, two M, etc.) and then creates a similar array for the current word read from
the file. The two arrays can be compared to see if the word from the file could be
created out of the letters from the entered word.
note: don't use chegg
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images