#K12291. Restoring the Corrupted String
Restoring the Corrupted String
Restoring the Corrupted String
You are given a corrupted string s
of length \( n \) in which some characters have been replaced by a question mark ('?'). You are also provided with a dictionary containing \( k \) candidate strings, each of length \( n \). Your task is to restore the original string by finding the string in the dictionary that matches the non-corrupted characters in \( s \).
More formally, for every position \( i \) (where \( 0 \leq i < n \)), the character \( s[i] \) is either a lowercase letter or a '?' character. A candidate string \( w \) from the dictionary is a valid restoration of \( s \) if for all \( i \), either \( s[i] = '?' \) or \( s[i] = w[i] \). It is guaranteed that for valid inputs, there is exactly one valid restoration.
Your program should read from standard input and print the restored string on standard output.
inputFormat
The input is given from standard input in the following format:
n s k word_1 word_2 ... word_k
Where:
- \( n \) is the length of the string.
- \( s \) is the corrupted string containing lowercase letters and '?' characters.
- \( k \) is the number of dictionary words.
- Each of the next \( k \) lines contains a candidate string of length \( n \).
outputFormat
Print the restored string on standard output.
## sample5
a?c?e
3
abcde
axcye
atcbe
abcde