Advertisement
horozov86

Stacked_Queries

May 5th, 2023 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. number = int(input())
  2.  
  3. my_stack = []
  4.  
  5. for _ in range(number):
  6.     query = input()
  7.    
  8.     query_split = query.split()
  9.     command = query_split[0]
  10.    
  11.     if command == "1":
  12.         current_number = int(query_split[1])
  13.         my_stack.append(current_number)
  14.        
  15.     elif command == "2" and my_stack:
  16.         my_stack.pop()
  17.    
  18.     elif command == "3" and my_stack:
  19.         print(max(my_stack))
  20.    
  21.     elif command == "4" and my_stack:
  22.         print(min(my_stack))
  23.    
  24.        
  25. reversed_stack = []        
  26. while my_stack:
  27.     reversed_stack.append(str(my_stack.pop()))
  28.    
  29. print(", ".join(reversed_stack))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement