Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. import math
  2.  
  3. units = {'kg': 1000, 'l': 1000, 'tens': 10}
  4. amount_of_dishes = int(input())
  5. finish_price = 0
  6. dishes = {}
  7. dishes_names = []
  8. dishes_count = {}
  9. dishes_products = {}
  10. products_counts = {}
  11. products_values = {}
  12. dish_values = {}
  13. for _ in range(amount_of_dishes):
  14.     dish_name, dish_count, dish_product_amount = input().split()
  15.     dish = {}
  16.     dishes_count[dish_name] = int(dish_count)
  17.     dish_values[dish_name] = [0, 0, 0, 0]
  18.     for _ in range(int(dish_product_amount)):
  19.         product, product_count, unit = input().split()
  20.         product_count = int(product_count) * units.get(unit, 1)
  21.         products_counts[product] = products_counts.get(product, 0) + product_count * int(dish_count)
  22.         dish[product] = product_count
  23.     dishes[dish_name] = dish
  24.     dishes_names.append(dish_name)
  25. amount_of_products = int(input())
  26. product_to_buy = {}
  27. for _ in range(amount_of_products):
  28.     product, price, count, unit = input().split()
  29.     if product not in products_counts:
  30.         continue
  31.     to_buy = math.ceil(products_counts[product] / (units.get(unit, 1) * int(count)))
  32.     product_to_buy[product] = to_buy
  33.     finish_price += int(price) * to_buy
  34. product_values = {}
  35. values_amount = int(input())
  36. for _ in range(values_amount):
  37.     product, count, unit, first, second, third, fourth = input().split()
  38.     values = list(map(lambda x: x / int(count) / units.get(unit, 1),
  39.                                             map(float, (first, second, third, fourth))))
  40.     product_values[product] = values
  41. for dish_name in dishes:
  42.     dish = dishes[dish_name]
  43.     for product_name in dish:
  44.         product_count = dish[product_name]
  45.         new_values = list(map(lambda x: product_count * x, product_values[product_name]))
  46.         new_values = list(map(lambda x: sum(x), zip(new_values, dish_values[dish_name])))
  47.         dish_values[dish_name] = new_values
  48.     for i in range(len(dish_values[dish_name])):
  49.         value = dish_values[dish_name][i]
  50.         if int(value) == value:
  51.             dish_values[dish_name][i] = int(value)
  52. print(finish_price)
  53. for product in product_to_buy:
  54.     print(product, product_to_buy[product])
  55. for dish_name in dish_values:
  56.     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