#K45482. Mirrored String Check
Mirrored String Check
Mirrored String Check
Given a set of character mappings, determine if a string is a mirrored string.
A string is considered mirrored if for every character in the first half of the string, its corresponding mirror (as defined by the given bidirectional mapping) matches the character in the corresponding position from the other end. If the string has an odd length, the middle character is ignored.
For example, if the mapping defines that 'a' maps to 'e' (and vice-versa), then the string "abpe" is mirrored since the mapping holds for the pair ('a','e') and ('b','p'). Otherwise, if any pair does not satisfy the mapping, the string is not mirrored.
inputFormat
The input is read from standard input and is structured as follows:
- The first line contains an integer T denoting the number of test cases.
- For each test case:
- The first line contains an integer N representing the number of mapping pairs.
- The next N lines each contain two space-separated characters specifying the mapping pair.
- The last line contains a string s that needs to be evaluated.
outputFormat
For each test case, output a single line to standard output. Print MIRRORED
if the string satisfies the mirror condition; otherwise, print NOT MIRRORED
.
4
2
a e
b p
abpe
3
h j
o p
k m
hop
1
a a
aaa
2
a e
b p
aebp
MIRRORED
NOT MIRRORED
MIRRORED
NOT MIRRORED
</p>