#K46762. Mutable String Operations
Mutable String Operations
Mutable String Operations
This problem requires you to implement a mutable string data structure that supports several operations to change the content of the string. The operations include:
- append c: Append character
c
to the end of the string. - insert i c: Insert character
c
into the string at indexi
(0-indexed). - delete i: Delete the character at index
i
(0-indexed). - reverse: Reverse the string.
- get: Output the current state of the string.
You will be given a sequence of operations. Every time a get
command is encountered, you should output the current state of the string.
For any indices provided, you may assume they are valid for the current string.
All operations should be processed in the order they are provided.
Formally, let \( S \) be the mutable string, then the operations are defined as follows:
- \( append\ c: \ S \mathrel{\Vert}\ c \)
- \( insert\ i\ c: \ S = S[0:i] + c + S[i:] \)
- \( delete\ i: \ S = S[0:i] + S[i+1:] \)
- \( reverse: \ S = reverse(S) \)
- \( get: Output the current state of \( S \) \)
inputFormat
The input is read from standard input (stdin) and has the following format:
N operation_1 operation_2 ... operation_N
Here, N
is an integer representing the number of operations. Each subsequent line contains one of the following operations: append c
, insert i c
, delete i
, reverse
, or get
.
outputFormat
For every get
operation encountered while processing the input, output the current state of the string on a new line to standard output (stdout). No additional output should be produced.
6
append a
append b
insert 1 z
get
delete 0
get
azb
zb
</p>