Long before digital messaging, telegraph operators saved transmission time by writing certain recurring letter groups in a compact shorthand. Every shorthand message is built by concatenating, one after another with no spaces or separators, any number of exactly three fixed tokens: the single character G, the two-character token (), and the four-character token (al). You are given a shorthand message guaranteed to be composed of nothing but these three token types, one after another. Expand it back into plain text by replacing every G with G, every () with o, and every (al) with al, joining the replacements in the same order the tokens appeared, and print the result.
A single line containing the shorthand message -- a string made only of the characters G, (, ), a, and l that parses uniquely as a concatenation of the tokens G, (), and (al).
Print the expanded plain-text message on a single line.
G, (), and (al) concatenated in some order, with no other characters presentExample 1
Input
(al)G()
Expected
alGo
Explanation
The tokens in order are (al), G, () which expand to al, G, o; concatenating gives alGo.
Example 2
Input
()()(al)G(al)
Expected
ooalGal
Explanation
The tokens in order are (), (), (al), G, (al) which expand to o, o, al, G, al; concatenating gives ooalGal.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →