#C7451. Stack Book Organizer
Stack Book Organizer
Stack Book Organizer
Raj has a stack of books he wants to organize. Each book is identified by a unique positive integer. He can perform three types of operations:
- Add: Push a book onto the top of the stack.
- Remove: Remove the book from the top of the stack (if the stack is not empty).
- Check: Check whether a book with a given ID is currently present in the stack. If it is, output "YES"; otherwise, output "NO".
You are given a series of operations. For each check operation, output the corresponding result. The operations are processed in the order given.
Note: The operations are described by a string and an integer. The integer represents the book ID. The operations are defined as follows:
\( \text{add:} \quad \text{Push the book onto the stack.} \)
\( \text{remove:} \quad \text{If the stack is non-empty, remove the top book.} \)
\( \text{check:} \quad \text{Output \( YES \) if the book is in the stack; otherwise, output \( NO \).} \)
inputFormat
The input is given via standard input. The first line contains a single integer \( n \) which denotes the number of operations. The next \( n \) lines each contain an operation in the format:
<operation> <book_id>
Where <operation>
is one of "add", "remove", or "check" and <book_id>
is a positive integer.
outputFormat
For every operation of type check, output a single line containing either "YES" or "NO" depending on whether the book with the given ID is in the stack at that moment.
## sample5
add 5
add 3
check 5
remove 3
check 3
YES
NO
</p>