#D7616. Broken Cipher Generator
Broken Cipher Generator
Broken Cipher Generator
Broken crypto generator
JAG (Japanese Alumni Group) is a mysterious organization composed of many programmers, and in order to enter the building where the headquarters of this organization is located, it is necessary to solve the ciphertext generated by a certain machine every time. This ciphertext consists of the symbols'+','-','[',']' and the uppercase alphabet, and is represented by defined by the following BNF.
:: = | :: = |'['']' :: ='+' |'-' | 'A' |'B' |'C' |'D' |'E' |'F' |'G' |'H' |'I' |'J' |'K' |'L' |'M '| 'N' |'O' |'P' |'Q' |'R' |'S' |'T' |'U' |'V' |'W' |'X' |'Y' |'Z '
Here, each symbol has the following meaning.
-
- (Character): Represents the alphabet following that character (provided that the alphabet following'Z'is'A') *-(Character): Represents the alphabet before that character (provided that the alphabet before'A'is'Z')
- [(Character string)]: Represents a character string that is horizontally inverted.
However, the machine that generates this ciphertext is currently out of order, and some letters of the alphabet in the ciphertext may be broken and unreadable. Unreadable characters are tentatively represented as'?'. As a result of the investigation, it was found that the method of filling the broken characters is such that the decrypted character string is the smallest in the dictionary order among the possible character strings after decoding. Your job is to decrypt this ciphertext correctly.
Input
The input consists of multiple datasets. Each dataset consists of one line containing a string in which some uppercase letters have been replaced with ‘?’ In the ciphertext defined by BNF above. You can assume that the length of each string is less than . You can also assume that the number of'?' In each dataset is greater than or equal to and less than or equal to .
The end of the input is represented by a line containing only one character,'.'.
Output
For each data set, output the decrypted character string when the ciphertext is decrypted so that the decrypted character string is the smallest in the dictionary order.
Sample Input
A + A ++ A Z-Z--Z + -Z [ESREVER] J ---? --- J ++++++++ A +++ Z ----------- A +++ Z [[++-+-? [-++-? ++-+++ L]] [-+ ----- + -O]] ++++ --- + L ..
Output for Sample Input
ABC ZYXZ REVERSE JAG ICPC JAPAN
Example
Input
A+A++A Z-Z--Z+-Z [ESREVER] J---?---J ++++++++A+++Z-----------A+++Z [[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L .
Output
ABC ZYXZ REVERSE JAG ICPC JAPAN
inputFormat
Input
The input consists of multiple datasets. Each dataset consists of one line containing a string in which some uppercase letters have been replaced with ‘?’ In the ciphertext defined by BNF above. You can assume that the length of each string is less than . You can also assume that the number of'?' In each dataset is greater than or equal to and less than or equal to .
The end of the input is represented by a line containing only one character,'.'.
outputFormat
Output
For each data set, output the decrypted character string when the ciphertext is decrypted so that the decrypted character string is the smallest in the dictionary order.
Sample Input
A + A ++ A Z-Z--Z + -Z [ESREVER] J ---? --- J ++++++++ A +++ Z ----------- A +++ Z [[++-+-? [-++-? ++-+++ L]] [-+ ----- + -O]] ++++ --- + L ..
Output for Sample Input
ABC ZYXZ REVERSE JAG ICPC JAPAN
Example
Input
A+A++A Z-Z--Z+-Z [ESREVER] J---?---J ++++++++A+++Z-----------A+++Z [[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L .
Output
ABC ZYXZ REVERSE JAG ICPC JAPAN
样例
A+A++A
Z-Z--Z+-Z
[ESREVER]
J---?---J
++++++++A+++Z-----------A+++Z
[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L
.
ABC
ZYXZ
REVERSE
JAG
ICPC
JAPAN
</p>