Mirror Brackets
InterviewTime limit1sMemory limit1024 MB
Given a string of mirror letters and brackets, apply the reflections until no brackets remain and print the final string.
- Level
Medium5 of 10
- Topics
- Stack, String, Simulation
- Solved
- No attempts yet
Problem
Let's recall what a correct bracket sequence (CBS) is.
- An empty string is a CBS.
- If is a CBS, then
()and[]are also CBS. - If and are CBS, then is also a CBS.
- A sequence that cannot be obtained by the rules above is not a CBS.
Vasya wrote a correct bracket sequence using the brackets "(", ")", "[" and "]". Then he inserted some of the characters "b", "d", "o", "p", "q" and "x" at various places in the sequence, which produced a string .
Vasya repeats the following operations.
If contains a substring of the form () (where has no brackets), he replaces it with the mirror reflection of across the vertical axis. If contains a substring of the form [] (where has no brackets), he replaces it with the mirror reflection of across the horizontal axis. For example, the substring "(qbpoxd)" becomes "bxoqdp", and the substring "[qbpoxd]" becomes "dpboxq".
Vasya keeps performing these operations until no brackets remain. Given , find the final string.
Input
The only line contains the string , whose length does not exceed . The string consists of the characters "(", ")", "[", "]", "b", "d", "o", "p", "q" and "x". It is guaranteed that the brackets in form a correct bracket sequence. It is also guaranteed that the input contains at least one letter.
Output
Print the final string that Vasya gets.