#B3998. Text Editor Simulation
Text Editor Simulation
Text Editor Simulation
You are given a text editor with a strange keyboard. The keyboard has 26 lowercase English letters and a backspace key. When a lowercase letter key is pressed, the corresponding letter is appended to the end of the current text. When the backspace key is pressed, the last letter of the current text is removed (if the text is nonempty). In other words, if the current text is T
and a lowercase letter c
is pressed, the new text becomes Tc
; if the backspace key is pressed and T
is nonempty, then the new text becomes \(T = T[0\ldots{(|T|-2)}]\).
Initially, the text is empty. Given a sequence of key presses, output the final text after processing all keystrokes.
inputFormat
The input begins with an integer n
(\(1 \leq n \leq 10^5\)), which represents the number of keystrokes. The following line contains n
tokens separated by spaces. Each token is either a lowercase English letter (which means that key is pressed) or the word backspace
(which means the backspace key is pressed).
outputFormat
Output a single line containing the final text after processing all n
keystrokes.
sample
6
a b c backspace d e
abde