Woburn Challenge 1999
Neo is trying to crack the code to break into the computer system of those omnipotent aliens. Whoa!! But even though he has been given the decryption algorithm by Morpheus, he still can't figure it out (remember, this is Keanu we're talking about here). So you need to help him break the code.
The system works as follows. The computer will give you a "challenge" -
an order set of at most characters, enclosed in round brackets ((
,
)
). To successfully enter the system, you have to answer the challenge
by permuting the order of the elements using the given. The correct
permutation is obtained by applying one or more permutation matrices to
the challenge string as follows: a permutation MATRIX of means
that the 1st character of the challenge string stays 1st, the 3rd
character is now 2nd and the 2nd character is now 3rd. So for example,
if the challenge set is and the permutation matrix is ,
the counterchallenge is . Like we said, there may be more than
one permutation matrix to apply in which case you apply them from right
to left. So if the challenge is and the permutation matrices are
, the counterchallenge is . And remember the wise
words of Morpheus (i.e. us): "everyone will be told what the matrix is."
Input Specification
The input will consist of , the number of elements in the set and the
actual matrices / set on the following line.
Each "matrix" will contain at most numbers, separated by spaces.
There will be at most matrices on each line.
There will be no spaces between any of the brackets ([
, ]
, (
, )
)
and any characters following. of denotes end of data.
No line of input will contain more than characters.
Output Specification
For each test case output the correct counterchallenge.
The output must contain one space separating each pair of set elements
(there are no spaces between the elements and the brackets!)
Sample Input
3
[3 2 1][1 3 2](a b c)
2
[2 1][2 1](a b)
-1
Sample Output
(b c a)
(a b)
Comments