Advertisement
ALEXANDAR_GEORGIEV

Exe 1

May 11th, 2023
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.09 KB | Source Code | 0 0
  1. # Balanced_parenteses
  2. from collections import deque
  3.  
  4. parenthesis = deque(input()) # ["(,
  5. open_parenthesis = deque()
  6.  
  7. while parenthesis:
  8.     current_parenthises = parenthesis.popleft()
  9.  
  10.     if current_parenthises in '({[':
  11.         open_parenthesis.append(current_parenthises)
  12.     elif not open_parenthesis:
  13.         print('NO')
  14.         break
  15.     else:
  16.         if f"{open_parenthesis.pop() + current_parenthises}" not  in "()[]{}":
  17.             print('NO')
  18.             break
  19.  
  20. else:
  21.     print('YES')
  22.  
  23. # Fashion_boutique
  24. from collections import deque
  25.  
  26. clothes = deque([int(x) for x in input().split()])
  27.  
  28. rack_space = int(input())
  29.  
  30. rack_count = 1
  31. current_rack_space = rack_space
  32.  
  33. while clothes:
  34.     cloth = clothes.pop()
  35.  
  36.     if current_rack_space >= cloth:
  37.         current_rack_space -= cloth
  38.     else:
  39.         rack_count += 1
  40.         current_rack_space = rack_space - cloth
  41.  
  42. print(rack_count)
  43.  
  44. # Fast_food
  45. from collections import deque
  46.  
  47. # solution 1
  48. food = int(input())
  49. orders = deque([int(x) for x in input().split()])
  50.  
  51.  
  52. print(max(orders))
  53.  
  54.  
  55. for order in orders.copy():
  56.     #if food - order >= 0:
  57.     if food >= order:
  58.         orders.popleft()
  59.         food -= order
  60.     else:
  61.         print(f"Order left: {' '.join([str(x) for x in orders])}")
  62.         break   # Няма да влезе в else
  63.  
  64. else:
  65.     print('Orders complete')
  66.  
  67. # Key_revolver
  68. from collections import deque
  69.  
  70.  
  71. bullet_price = int(input())
  72. mag_max = int(input())
  73.  
  74. bullets = deque([int(b) for b in input().split()])
  75. locks = deque([int(l) for l in input().split()])
  76.  
  77. reward = int(input())
  78.  
  79. bullets_in_mag = mag_max
  80. bullets_shot = 0
  81.  
  82. while bullets and locks:
  83.     bullet = bullets.pop()
  84.     lock = locks.popleft()
  85.  
  86.     if bullet <= lock:
  87.         print("Bang!")
  88.     else:
  89.         print("Ping!")
  90.         locks.appendleft(lock)
  91.  
  92.     bullets_in_mag -= 1
  93.     bullets_shot += 1
  94.  
  95.     if bullets_in_mag == 0 and bullets:
  96.         bullets_in_mag = mag_max if len(bullets) >= mag_max else len(bullets)
  97.         print("Reloading!")
  98.  
  99. if locks:
  100.     print(f"Couldn't get through. Locks left: {len(locks)}")
  101. else:
  102.     earned_money = abs((bullet_price * bullets_shot) - reward)
  103.     print(f"{len(bullets)} bullets left. Earned ${earned_money}")
  104.  
  105. # Revers_numbers
  106. # stack
  107. from collections import deque
  108.  
  109. # solution 1
  110. numbers = deque(input().split())
  111.  
  112. for _ in range(len(numbers)):
  113.     print(numbers.pop(), end=' ')
  114.  
  115. # solution 2
  116. numbers = deque(input().split())
  117. numbers.reverse()
  118. print(' '.join(numbers), sep=' ')
  119.  
  120. # Robotics
  121. from collections import deque
  122. from datetime import datetime, timedelta
  123.  
  124.  
  125. robots = {
  126.  
  127. }
  128.  
  129. for r in input().split(";"):
  130.     name, time_needed = r.split("-")
  131.     robots[name] = [int(time_needed), 0]
  132.  
  133. factory_time = datetime.strptime(input(), "%H:%M:%S")
  134.  
  135. products = deque()
  136.  
  137. while True:
  138.     product = input()
  139.  
  140.     if product == 'End':
  141.         break
  142.  
  143.     products.append(product)
  144.  
  145. while products:
  146.     factory_time += timedelta(0, 1)
  147.     product = products.popleft()
  148.  
  149.     free_robots = []
  150.  
  151.     for name, value in robots.items():
  152.         if value[1] != 0:
  153.             robots[name][1] -= 1
  154.  
  155.         if value[1] == 0:
  156.             free_robots.append([name, value])
  157.  
  158.     if not free_robots:
  159.         products.append(product)
  160.         continue
  161.  
  162.     robot_name, data = free_robots[0]
  163.     robots[robot_name][1] = data[0]
  164.  
  165.     print(f"{robot_name} - {product} [{factory_time.strftime('%H:%M:%S')}]")
  166.  
  167. print(robots)
  168.  
  169. # Stacked_queries
  170. from collections import deque
  171.  
  172. # solution 1
  173. numbers = deque()
  174.  
  175. for _ in range(int(input())):
  176.     number_data = [int(x) for x in input().split()]
  177.     command = number_data[0]
  178.  
  179.     if command == 1:
  180.         numbers.append(number_data[1])
  181.     elif command == 2:
  182.         if numbers:
  183.             numbers.pop()
  184.     elif command == 3:
  185.         if numbers:
  186.             print(max(numbers))
  187.     elif command == 4:
  188.         if numbers:
  189.             print(min(numbers))
  190.  
  191. numbers.reverse()
  192.  
  193. print(*numbers, sep=', ')   # разопаковане ?
  194.  
  195. # solution 2
  196. numbers = deque()
  197.  
  198. map_function = {
  199.     1: lambda x: numbers.append(x[1]),
  200.     2: lambda x: numbers.pop() if numbers else None,
  201.     3: lambda x: print(max(numbers)) if numbers else None,
  202.     4: lambda x: print(min(numbers)) if numbers else None
  203. }
  204.  
  205. for _ in range(int(input())):
  206.     number_data = [int(x) for x in input().split()]
  207.     map_function[number_data[0]](number_data)   # в скобите, караме да се изпълни функцията lambda
  208.  
  209.  
  210.  
  211. numbers.reverse()
  212.  
  213. print(*numbers, sep=', ')   # разопаковане ?
  214.  
  215. # Truck_tour
  216. from collections import deque
  217.  
  218. pumps_data = deque([[int(x) for x in input().split()] for _ in range(int(input()))])   # Списък в списък
  219.  
  220. pumps_data_copy = pumps_data.copy()
  221. gas_in_tank = 0
  222. index = 0
  223.  
  224. while pumps_data_copy:
  225.     petrol, distance = pumps_data_copy.popleft()
  226.  
  227.     gas_in_tank += petrol
  228.  
  229.     if gas_in_tank >= distance:
  230.         gas_in_tank -= distance
  231.     else:
  232.         pumps_data.rotate(-1)
  233.         pumps_data_copy = pumps_data.copy()
  234.         index += 1
  235.  
  236. print(index)
  237.  
  238.  
  239.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement