Advertisement
Nenogzar

2. Stacked Queries

May 14th, 2024
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. stack = []
  2.  
  3. def delete():
  4.     stack.pop()
  5.  
  6. def print_max():
  7.     max_value = max(stack)
  8.     print(*max_value)
  9.  
  10. def print_min():
  11.     min_value = min(stack)
  12.     print(*min_value)
  13.  
  14. commands = {
  15.     '2': delete,
  16.     '3': print_max,
  17.     '4': print_min
  18. }
  19.  
  20. # N = int(input())
  21. # for _ in range(N):
  22. #     query = input().split()
  23. #     command = query[0]
  24. #     if command == '1':
  25. #         number = int(query[1])
  26. #         commands[command](number)
  27. #     else:
  28. #         commands[command]()
  29.  
  30. N = int(input())
  31. for _ in range(N):
  32.     command, *numbers = input().split()
  33.     if command == '1':
  34.         number = [int(num) for num in numbers]
  35.         stack.append(number)
  36.     else:
  37.         if stack:
  38.             commands[command]()
  39.  
  40. reversed_stack = reversed(stack)
  41. print(', '.join(str(*item) for item in reversed_stack))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement