| CodeRams Practice Problem Archive |
|---|
| Finished |
You have a string, consisting of at most seven characters, not including spaces. You want to find all of the anagrams of the string. A string $$$t$$$ is defined as an anagram of a string $$$s$$$ if an only if the characters of $$$s$$$, in sorted order, not including spaces, are equal to the characters of $$$t$$$, in sorted order, not including spaces.
You're also given a dictionary of $$$n$$$ words.
An anagram is considered a valid anagram if it consists of only space-separated words that are in the dictionary. For example, if the dictionary was the English dictionary, hello and hello world would be valid anagrams, but he llo and helloworld would not be valid anagrams.
Given the string, and the dictionary, print all of the valid anagrams of the string, in alphabetical order.
The first line of input contains a single string $$$s$$$, possibly containing spaces. $$$s$$$ will have less than or equal to seven characters, not including spaces.
The next line of input consists of a single positive integer $$$n$$$, indicating how many words are in the dictionary.
The next $$$n$$$ lines each contain a word not containing spaces: each dictionary entry.
Output all of the words or phrases that are valid anagrams of the given string, in alphabetical order. Make sure not to repeat words, i.e. all of the answers should be distinct.
coderam 12 arm codes dore smac do res mac armcodes blahblah coderam rams code
arm code code arm coderam dore mac mac dore
hello 5 he ll o hel lo
he ll o he o ll hel lo ll he o ll o he lo hel o he ll o ll he
| Name |
|---|


