Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- units = {'kg': 1000, 'l': 1000, 'tens': 10}
- amount_of_dishes = int(input())
- finish_price = 0
- dishes = {}
- dishes_names = []
- dishes_count = {}
- dishes_products = {}
- products_counts = {}
- products_values = {}
- dish_values = {}
- for _ in range(amount_of_dishes):
- dish_name, dish_count, dish_product_amount = input().split()
- dish = {}
- dishes_count[dish_name] = int(dish_count)
- dish_values[dish_name] = [0, 0, 0, 0]
- for _ in range(int(dish_product_amount)):
- product, product_count, unit = input().split()
- product_count = int(product_count) * units.get(unit, 1)
- products_counts[product] = products_counts.get(product, 0) + product_count * int(dish_count)
- dish[product] = product_count
- dishes[dish_name] = dish
- dishes_names.append(dish_name)
- amount_of_products = int(input())
- product_to_buy = {}
- for _ in range(amount_of_products):
- product, price, count, unit = input().split()
- if product not in products_counts:
- continue
- to_buy = math.ceil(products_counts[product] / (units.get(unit, 1) * int(count)))
- product_to_buy[product] = to_buy
- finish_price += int(price) * to_buy
- product_values = {}
- values_amount = int(input())
- for _ in range(values_amount):
- product, count, unit, first, second, third, fourth = input().split()
- values = list(map(lambda x: x / int(count) / units.get(unit, 1),
- map(float, (first, second, third, fourth))))
- product_values[product] = values
- for dish_name in dishes:
- dish = dishes[dish_name]
- for product_name in dish:
- product_count = dish[product_name]
- new_values = list(map(lambda x: product_count * x, product_values[product_name]))
- new_values = list(map(lambda x: sum(x), zip(new_values, dish_values[dish_name])))
- dish_values[dish_name] = new_values
- for i in range(len(dish_values[dish_name])):
- value = dish_values[dish_name][i]
- if int(value) == value:
- dish_values[dish_name][i] = int(value)
- print(finish_price)
- for product in product_to_buy:
- print(product, product_to_buy[product])
- for dish_name in dish_values:
- print(dish_name, *map(lambda x: "{:.3f}".format(x) if isinstance(x, float) else x, dish_values[dish_name]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement