#C8978. Anagram Finder
Anagram Finder
Anagram Finder
Given a string \(s\) and a dictionary of words, your task is to find all unique valid anagrams of \(s\) that appear in the dictionary. An anagram is any rearrangement of the characters of \(s\). The total number of possible permutations is given by \(n!\), where \(n\) is the length of the string \(s\). The output should be sorted in lexicographical order.
Example:
Input: ate 6 eat tea tan ate nat bat</p>Output: ate eat tea
If there are no valid anagrams, print an empty line.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains the string \(s\).
- The second line contains an integer \(n\), representing the number of words in the dictionary.
- The following \(n\) lines each contain one word from the dictionary.
outputFormat
Print a single line to standard output (stdout) containing all valid anagrams of \(s\) that exist in the dictionary, sorted in lexicographical order and separated by a single space. If there are no valid anagrams, output an empty line.
## sampleate
6
eat
tea
tan
ate
nat
bat
ate eat tea