#C6626. Decode Encoded Strings
Decode Encoded Strings
Decode Encoded Strings
You are given an encoded string. The encoding rule is defined as $k\left[encoded\_string\right]$, where the encoded_string
inside the square brackets is repeated exactly $k$ times. Note that $k$ is a positive integer. You may assume that the input string is always valid and that there are no extra white spaces in the string.
Examples:
- For the input
3[a]2[bc]
, the output isaaabcbc
. - For the input
3[a2[c]]
, the output isaccaccacc
. - For the input
2[abc]3[cd]ef
, the output isabcabccdcdcdef
.
Your task is to decode the string and output the decoded version. Use appropriate algorithms to handle nested encoded expressions.
inputFormat
The input consists of a single line containing the encoded string s
. The string will only contain digits, letters, and the characters [
and ]
which form a valid encoding as described above.
outputFormat
Output the decoded string corresponding to the given encoded string.
## sample3[a]2[bc]
aaabcbc