#C5753. String Operations Processor

    ID: 49437 Type: Default 1000ms 256MiB

String Operations Processor

String Operations Processor

You are given an initial string A and a sequence of operations to perform on it. The operations are one of the following:

  • Append(c): Append the character c to the end of the string.
  • Remove(): Remove the last character of the string.
  • Print(): Output the current string.

The operations are executed sequentially. When a Print() operation is encountered, the current string is printed on a new line.

Note: The string always starts with A. It is guaranteed that the operations will be valid so that the string never becomes undefined.

Mathematical Description:

If we denote the current string by \( S \) (initially \( S = A \)), then:

  • For an operation \( Append(c) \): \( S \leftarrow S + c \).
  • For an operation \( Remove() \): \( S \leftarrow S[0:|S|-1] \) (i.e. remove the last character).
  • For an operation \( Print() \): Output the current \( S \).

inputFormat

The input is given from the standard input (stdin) with the following format:

N
operation_1
operation_2
...
operation_N

Where N (an integer) is the number of operations, and each subsequent line represents an operation. Each operation is a string in one of the formats Append(c), Remove(), or Print().

outputFormat

For each Print() operation, output the current string on a new line to the standard output (stdout). If no Print() operation is executed, output nothing.

## sample
7
Append(B)
Append(C)
Print()
Remove()
Print()
Append(D)
Print()
ABC

AB ABD

</p>