Guest User

Untitled

a guest
Nov 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. n = int(input())
  2.  
  3. stack = []
  4. for i in range(n):
  5. inp = input().split()
  6. if len(inp) >= 2:
  7. if inp[0] == 'push':
  8. stack.append(inp[1])
  9. else:
  10. if inp[0] == 'pop':
  11. if len(stack) == 0:
  12. print(-1)
  13. else:
  14. pop = stack.pop()
  15. print(pop)
  16. elif inp[0] == 'size':
  17. print(len(stack))
  18. elif inp[0] == 'empty':
  19. if len(stack) == 0:
  20. print(1)
  21. else:
  22. print(0)
  23. elif inp[0] == 'top':
  24. if len(stack) == 0:
  25. print(-1)
  26. else:
  27. print(stack[len(stack)-1])
Add Comment
Please, Sign In to add comment