Anagrams II
30 points, Target Date: July 23 11:59pm
Your assignment is to write a program that reads in a dictionary of
words from a text file, reads in a single word from the user, and then
prints out all words in the dictionary that are anagrams
of that word. Further, your program must execute completely
within 1 second when executed on the server hill.cs.ucr.edu.
Details
Your program needs to use file streams (more information here) to
read in the file /usr/share/dict/words, the standard English
dictionary under most Linux distributions. For up to 3% bonus credit
you may add a command line flag to specify an alternate dictionary,
but you must read in that dictionary as a default. If the preceeding
sentence doesn't make any sense to you, ask someone or Google for it.
You also must read in a single word from standard input (using
cin). Upon reading in that word, print out all anagrams of the
word that are found in the dictionary, in alphabetic order.
No other output should be generated.
To achieve real efficiency you may need to use a different data
structure to store the dictionary. If the size of the dictionary
(number of entries) is greater than the number of permutations
(possible anagrams) of the chosen word, then store the dictionary in a
hash table and then generate all permutations, checking them against
the dictionary. If the size of the dictionary is less than the number
of permutations, then you may simply read the dictionary into an array
or a vector and iterate through it linearly.
Downloads
A compiled binary sample of the program that you can test against can
be found here
Sample input/output files (save to disk):
anagram1.in
anagram1.out
anagram2.in
anagram2.out
anagram3.in
anagram3.out
These tests can be run against your program using standard Unix I/O
redirection and the diff utility.
> ./anagram < anagram1.in | diff - anagram1.out
> ./anagram < anagram2.in | diff - anagram2.out
> ./anagram < anagram3.in | diff - anagram3.out
If any of these commands produce any output, your solution is incorrect.