Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Expression_eveluator
- from collections import deque
- from math import floor
- expression = deque(input().split())
- idx = 0
- while idx < len(expression):
- element = expression[idx]
- # eval() # Прави стринга в числа
- if element == "*":
- for _ in range(idx - 1):
- expression.appendleft(int(expression.popleft()) * int(expression.popleft()))
- elif element == "/":
- for _ in range(idx - 1):
- expression.appendleft(int(expression.popleft()) / int(expression.popleft()))
- elif element == "+":
- for _ in range(idx - 1):
- expression.appendleft(int(expression.popleft()) + int(expression.popleft()))
- elif element == "-":
- for _ in range(idx - 1):
- expression.appendleft(int(expression.popleft()) - int(expression.popleft()))
- if element in "*/+-":
- del expression[1]
- idx = 1
- idx += 1
- print(floor(int(expression[0])))
- # Solution 2
- from math import floor
- from functools import reduce
- expression = input().split()
- idx = 0
- functions = {
- "*": lambda i: reduce(lambda a, b: a * b, map(int, expression[:i])),
- "/": lambda i: reduce(lambda a, b: a / b, map(int, expression[:i])),
- "+": lambda i: reduce(lambda a, b: a + b, map(int, expression[:i])),
- "-": lambda i: reduce(lambda a, b: a - b, map(int, expression[:i]))
- }
- while idx < len(expression):
- element = expression[idx]
- if element in "*/+-":
- expression[0] = functions[element](idx)
- [expression.pop(1) for i in range(idx)]
- idx = 1
- idx += 1
- print(floor(int(expression[0])))
- # Honey
- from collections import deque
- bees = deque(int(x) for x in input().split())
- nectar = deque(int(x) for x in input().split())
- symbols = deque(input().split())
- total_honey = 0
- operations = {
- "*": lambda x, y: x * y,
- "/": lambda x, y: x / y,
- "+": lambda x, y: x + y,
- "-": lambda x, y: x - y,
- }
- while bees and nectar:
- curr_bee = bees.popleft()
- curr_nectar = nectar.pop()
- if curr_nectar < curr_bee:
- bees.appendleft(curr_bee)
- elif curr_nectar > curr_bee:
- total_honey += abs(operations[symbols.popleft()](curr_bee, curr_nectar))
- print(f"Total honey made: {total_honey}")
- if bees:
- print(f"Bees left: {', '.join(str(x) for x in bees)}")
- if nectar:
- print(f"Nectar left: {', '.join(str(x) for x in nectar)}")
- # Milkshakes
- from collections import deque
- chocolates = deque(int(x) for x in input().split(", "))
- cups_of_milk = deque(int(x) for x in input().split(", "))
- milkshakes = 0
- while milkshakes != 5 and chocolates and cups_of_milk:
- chocolate = chocolates.pop()
- cup_of_milk = cups_of_milk.pop()
- if chocolate <= 0 and cup_of_milk <= 0:
- continue
- elif chocolate <= 0:
- cups_of_milk.appendleft(cup_of_milk)
- continue
- elif cup_of_milk <= 0:
- chocolates.append(chocolate)
- continue
- if chocolate == cup_of_milk:
- milkshakes += 1
- else:
- cups_of_milk.append(cup_of_milk)
- chocolates.append(chocolate - 5)
- if milkshakes == 5:
- print("Greates!")
- else:
- print("Not enough milkshakes")
- print(f"Chokolate: {', '.join(str(x) for x in chocolates) or 'empty' }")
- print(f"Milk: {', '.join(str(x) for x in cups_of_milk) or 'empty' }")
- # Numbers
- first = set(int(x) for x in input().split())
- second = set(int(x) for x in input().split())
- for _ in range(int(input())):
- first_command, second_command, *data = input().split() # Вземи всичко след първите 2 елемента и го раопакояй отделно за всичко
- command = first_command + " " + second_command
- if command == " Add First":
- [first.add(int(el)) for el in data]
- elif command == "Add Second":
- [second.add(int(el)) for el in data]
- elif command == "Remove First":
- [first.discard(int(el)) for el in data]
- elif command == "Remove Second":
- [second.discard(int(el)) for el in data]
- else:
- print(first.issubset(second) or second.issubset(first)) # Връща True or False
- print(*sorted(first), sep=", ")
- print(*sorted(second), sep=", ")
- # Вместо IF -> Solution 2
- first = set(int(x) for x in input().split())
- second = set(int(x) for x in input().split())
- function = {
- "Add First": lambda x: [first.add(el) for el in data],
- "Add Second": lambda x: [second.add(el) for el in data],
- "Remove First": lambda x: [first.discard(el) for el in data],
- "Remove Second": lambda x: [second.discard(el) for el in data],
- "Check Subset": lambda x: print(first.issubset(second) or second.issubset(first)) # Връща True or False
- }
- for _ in range(int(input())):
- first_command, second_command, *data = input().split() # Вземи всичко след първите 2 елемента и го раопакояй отделно за всичко
- command = first_command + " " + second_command
- function[command](int(x) for x in data)
- print(*sorted(first), sep=", ")
- print(*sorted(second), sep=", ")
- # Paint_colors
- from collections import deque
- words = deque(input().split())
- colors = {"red", "yellow", "blue", "orange", "purple", "green"}
- req_colors = {
- "orange": {"yellow", "red"},
- "purple": {"red", "blue"},
- "green": {"yellow", "blue"}
- }
- result = []
- while words:
- first_word = words.popleft()
- second_word = words.pop() if words else ""
- for color in (first_word + second_word, second_word + first_word):
- if color in colors:
- result.append(color)
- break
- else:
- for el in (first_word[:-1], second_word[:-1]):
- if el:
- words.insert(len(words) // 2, el)
- for color in set(req_colors.keys()).intersection(result):
- if not req_colors[color].issubset(result):
- result.remove(color)
- print(result)
- # Santas_present_factory
- from collections import deque
- materials = deque(int(x) for x in input().split())
- magic_levels = deque(int(x) for x in input().split())
- crafted = []
- presents = {
- 150: "Doll",
- 250: "Wooden train",
- 300: "Teddy bear",
- 400: "Bicycle"
- }
- while materials and magic_levels:
- material = materials.pop() if magic_levels[0] or not materials[0] else 0
- magic_levels = magic_levels.pop() if material or not magic_levels[0] else 0
- if not magic_levels:
- continue
- product = material * magic_levels
- if presents.get(product):
- crafted.append(presents[product])
- elif product < 0:
- materials.append(material + magic_levels)
- elif product > 0:
- materials.append(material + 15)
- if {"Doll", "Wooden train"}.issubset(crafted) or {"Teddy bear", "Bicycle"}.issubset(crafted):
- print("The presents...")
- else:
- print("No presents this Cristmas!")
- if materials:
- print(f"Materials left: {', '.join(str(x) for x in materials[::-1])}")
- if magic_levels:
- print(f"Magic left: {', '.join([str(x) for x in magic_levels])}")
- [print(f"{toy}: {crafted.count(toy)}") for toy in sorted(set(crafted))]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement