← 返回 meta 的题目列表Text Transformation Simulation with Stack
类型:online_judge
Write a simulation program to process a series of three types of operations to transform an initial string of text. Input the initial string and a set of commands, where each command can be one of the following three types:
Append a character to the end of the text.
Remove the last character from the text.
Print the current text.
Input format:
The first line is the initial string s.
The next n lines denote n instructions, each in the form of either ‘ADD x’ or ‘REMOVE’.
Output format:
For each “PRINT” instruction, output the current string.
Example:
Input:
abc
3
ADD x
REMOVE
PRINT
Output:
ab
Constraints:
1 <= len(s) <= 1000
1 <= n <= 1000
Example
Input
abc
3
ADD x
REMOVE
PRINT