#C4999. Find and Replace Pattern
Find and Replace Pattern
Find and Replace Pattern
You are given a list of words and a pattern string. A word matches the pattern if and only if there exists a bijection between letters in the pattern and letters in the word. In other words, two letters in the pattern must map to the same letter in the word if and only if they are the same letter. Formally, for a given word \(w\) and pattern \(p\) of equal lengths, there exists a one-to-one mapping \(f\) such that \(f(p_i)=w_i\) for all valid indices \(i\).
Your task is to output all the words that match the given pattern in the order they appear in the input.
Note: Use the standard input/output for reading input and printing output.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains a non-empty string representing the
pattern
. - The second line contains an integer
n
representing the number of words. - The next
n
lines each contain a single word.
It is guaranteed that all words and the pattern have lengths between 1 and 100, inclusive.
outputFormat
Print (to standard output) a single line containing the words that match the given pattern in their original order. Words should be separated by a single space. If no words match, print an empty line.
## sampleabb
6
abc
deq
mee
aqq
dkd
ccc
mee aqq
</p>