#K65742. Find Anagrams
Find Anagrams
Find Anagrams
Given a target word and a list of candidate words, your task is to find all the candidates that are anagrams of the target word. An anagram is a word formed by rearranging the letters of another word, using all the original letters exactly once.
For example, for the word \(listen\) and the candidate list [\(enlist\), \(google\), \(inlets\), \(banana\)], the anagrams are \(enlist\) and \(inlets\).
Your program should read input from stdin
and output the anagrams (if any) to stdout
in the same order they appear in the input. If there are no anagrams, output an empty line.
inputFormat
The input consists of three parts:
- The first line contains a single word, the target word.
- The second line contains an integer \(n\), the number of candidate words.
- The third line contains \(n\) space-separated words representing the candidate words.
outputFormat
Output a single line containing the candidate words that are anagrams of the target word, separated by a space, in the same order as they appear in the input. If no candidate word is an anagram of the target word, output an empty line.
## samplelisten
4
enlist google inlets banana
enlist inlets
</p>