#K35417. Taco Bookshelf Tracker
Taco Bookshelf Tracker
Taco Bookshelf Tracker
You are given a sequence of commands representing operations on Maria's bookshelf. Each command is either an addition command or a removal command. An addition command is in the form A x
, which means to add the book with identifier x to the right end of the bookshelf. A removal command is in the form R x
, which means to remove the first occurrence of the book with identifier x from the bookshelf, if it exists.
After processing all commands, print the final order of book identifiers on the bookshelf. If the bookshelf is empty, print an empty line.
Note: The operations are performed in the order they are given.
inputFormat
The first line of input contains an integer n representing the number of commands.
The following n lines each contain a command in one of the following formats:
A x
to add a book with identifier xR x
to remove the book with identifier x (if it exists)
outputFormat
Print the final order of book identifiers on the bookshelf in a single line separated by a space. If the bookshelf is empty, output an empty line.
All outputs should be printed to standard output.
## sample7
A 5
A 10
R 5
A 15
A 5
R 10
A 20
15 5 20