#C673. Decode Lantern Sequence
Decode Lantern Sequence
Decode Lantern Sequence
In this problem, you are given an encoded lantern sequence which represents a hidden message. The encoding is based on a set of patterns. Each pattern consists of a unique character and its corresponding binary representation. The binary sequence is obtained by concatenating the binary patterns corresponding to characters in the message. Your task is to decode the lantern sequence and retrieve the original message.
Formally, you are given an integer (the number of patterns) and an integer (the length of the binary sequence). Then, you are provided with lines, each containing a single character and its corresponding binary pattern. Finally, you are given the binary sequence of length . It is guaranteed that all binary patterns have the same length, say . The sequence is formed by concatenating the binary codes without any delimiters. You should split the sequence into segments of length each, and replace each segment with the corresponding character.
For example, if , the mapping is: [ A \to 110, ; B \to 011, ; C \to 101 ] and the binary sequence is "110011101", then splitting into segments: "110", "011", "101" yields the decoded message "ABC".
Your solution must read from standard input and write the result to standard output.
inputFormat
The first line contains two integers and , where is the number of patterns and is the length of the binary sequence. The next lines each contain a character and its corresponding binary pattern (separated by space). The final line contains a binary string of length representing the encoded lantern sequence.
outputFormat
Output a single line containing the decoded message.## sample
3 9
A 110
B 011
C 101
110011101
ABC