Stack manipulation

Report a typo

You have the number n and a sequence of n stack operations, you need to print out the content of the stack after performing them (starting from the top element).

You can assume that originally the stack is empty.

Input:

The first line is the number n. The next n lines represent stack operations in the format: OPERATION [element]. Work with the input and process the given operations.

Output:

Elements in the stack, from top to bottom, each on a new line.

You can use split(" ") to split the input string on the whitespace.

Sample Input 1:

4
PUSH 1
PUSH 10
POP
PUSH 8

Sample Output 1:

8
1
Write a program in Python 3





___

Create a free account to access the full topic