CJCoding With Joseph
15free / daySign inCreate account

Write a program that simulates a tiny text editor with undo. Read commands from standard input until the input ends. Each command is on its own line and is one of: - add WORD — push WORD (a single word with no spaces) onto a stack<string> - undo — remove the most recently added word; if there are no words, do nothing - print — print all current words in the order they were added (oldest first, newest last), separated by single spaces, followed by a newline; if there are no words print the line (empty)

Only print produces output.

Input example: add hello add world print undo print

Expected output

hello world
hello
(empty)
a b

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
STL ContainersStacks
Auto-input
add hello\nadd world\nprint\nundo\nprint\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.