Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Balanced_parenteses
- from collections import deque
- parenthesis = deque(input()) # ["(,
- open_parenthesis = deque()
- while parenthesis:
- current_parenthises = parenthesis.popleft()
- if current_parenthises in '({[':
- open_parenthesis.append(current_parenthises)
- elif not open_parenthesis:
- print('NO')
- break
- else:
- if f"{open_parenthesis.pop() + current_parenthises}" not in "()[]{}":
- print('NO')
- break
- else:
- print('YES')
- # Fashion_boutique
- from collections import deque
- clothes = deque([int(x) for x in input().split()])
- rack_space = int(input())
- rack_count = 1
- current_rack_space = rack_space
- while clothes:
- cloth = clothes.pop()
- if current_rack_space >= cloth:
- current_rack_space -= cloth
- else:
- rack_count += 1
- current_rack_space = rack_space - cloth
- print(rack_count)
- # Fast_food
- from collections import deque
- # solution 1
- food = int(input())
- orders = deque([int(x) for x in input().split()])
- print(max(orders))
- for order in orders.copy():
- #if food - order >= 0:
- if food >= order:
- orders.popleft()
- food -= order
- else:
- print(f"Order left: {' '.join([str(x) for x in orders])}")
- break # Няма да влезе в else
- else:
- print('Orders complete')
- # Key_revolver
- from collections import deque
- bullet_price = int(input())
- mag_max = int(input())
- bullets = deque([int(b) for b in input().split()])
- locks = deque([int(l) for l in input().split()])
- reward = int(input())
- bullets_in_mag = mag_max
- bullets_shot = 0
- while bullets and locks:
- bullet = bullets.pop()
- lock = locks.popleft()
- if bullet <= lock:
- print("Bang!")
- else:
- print("Ping!")
- locks.appendleft(lock)
- bullets_in_mag -= 1
- bullets_shot += 1
- if bullets_in_mag == 0 and bullets:
- bullets_in_mag = mag_max if len(bullets) >= mag_max else len(bullets)
- print("Reloading!")
- if locks:
- print(f"Couldn't get through. Locks left: {len(locks)}")
- else:
- earned_money = abs((bullet_price * bullets_shot) - reward)
- print(f"{len(bullets)} bullets left. Earned ${earned_money}")
- # Revers_numbers
- # stack
- from collections import deque
- # solution 1
- numbers = deque(input().split())
- for _ in range(len(numbers)):
- print(numbers.pop(), end=' ')
- # solution 2
- numbers = deque(input().split())
- numbers.reverse()
- print(' '.join(numbers), sep=' ')
- # Robotics
- from collections import deque
- from datetime import datetime, timedelta
- robots = {
- }
- for r in input().split(";"):
- name, time_needed = r.split("-")
- robots[name] = [int(time_needed), 0]
- factory_time = datetime.strptime(input(), "%H:%M:%S")
- products = deque()
- while True:
- product = input()
- if product == 'End':
- break
- products.append(product)
- while products:
- factory_time += timedelta(0, 1)
- product = products.popleft()
- free_robots = []
- for name, value in robots.items():
- if value[1] != 0:
- robots[name][1] -= 1
- if value[1] == 0:
- free_robots.append([name, value])
- if not free_robots:
- products.append(product)
- continue
- robot_name, data = free_robots[0]
- robots[robot_name][1] = data[0]
- print(f"{robot_name} - {product} [{factory_time.strftime('%H:%M:%S')}]")
- print(robots)
- # Stacked_queries
- from collections import deque
- # solution 1
- numbers = deque()
- for _ in range(int(input())):
- number_data = [int(x) for x in input().split()]
- command = number_data[0]
- if command == 1:
- numbers.append(number_data[1])
- elif command == 2:
- if numbers:
- numbers.pop()
- elif command == 3:
- if numbers:
- print(max(numbers))
- elif command == 4:
- if numbers:
- print(min(numbers))
- numbers.reverse()
- print(*numbers, sep=', ') # разопаковане ?
- # solution 2
- numbers = deque()
- map_function = {
- 1: lambda x: numbers.append(x[1]),
- 2: lambda x: numbers.pop() if numbers else None,
- 3: lambda x: print(max(numbers)) if numbers else None,
- 4: lambda x: print(min(numbers)) if numbers else None
- }
- for _ in range(int(input())):
- number_data = [int(x) for x in input().split()]
- map_function[number_data[0]](number_data) # в скобите, караме да се изпълни функцията lambda
- numbers.reverse()
- print(*numbers, sep=', ') # разопаковане ?
- # Truck_tour
- from collections import deque
- pumps_data = deque([[int(x) for x in input().split()] for _ in range(int(input()))]) # Списък в списък
- pumps_data_copy = pumps_data.copy()
- gas_in_tank = 0
- index = 0
- while pumps_data_copy:
- petrol, distance = pumps_data_copy.popleft()
- gas_in_tank += petrol
- if gas_in_tank >= distance:
- gas_in_tank -= distance
- else:
- pumps_data.rotate(-1)
- pumps_data_copy = pumps_data.copy()
- index += 1
- print(index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement