Advertisement
Guest User

Untitled

a guest
May 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. import math
  2. from operator import itemgetter
  3.  
  4. count = int(input())
  5.  
  6. rows = [input().strip() for i in range(count)]
  7.  
  8. # rows = [
  9. #     "Космопит (300 г): Крем-суп грибной - 400, Борщ - 410",
  10. #     "АстроЕда (150 г): Борщ - 210, Крем-суп грибной - 220"
  11. # ]
  12.  
  13.  
  14. items = []
  15. global_eats = {}
  16. for row in rows:
  17.     brandAndWeight, eats = row.split(': ')
  18.     brand, weight = brandAndWeight.split(' (')
  19.     weight = weight.replace(' г)', '')
  20.     eats = eats.split(', ')
  21.     for eat in eats:
  22.         name, price = eat.split(' - ')
  23.         cost = math.ceil(300 / int(weight)) * int(price)
  24.         items.append({
  25.             'brand': brand,
  26.             'name': name,
  27.             'price': price,
  28.             'cost': cost,
  29.             'weight': math.ceil(300 / int(weight)) * int(weight)
  30.         })
  31.  
  32.         if name in global_eats:
  33.             global_eats[name] += cost
  34.         else:
  35.             global_eats[name] = cost
  36.  
  37. global_eats = sorted(global_eats.items(), key = lambda i: i[1])
  38.  
  39. items = sorted(items, key=lambda i: i['cost'])
  40. items.reverse()
  41. brandname = ''
  42. eatname = global_eats[0][0]
  43.  
  44. print(eatname + ':')
  45.  
  46. for item in items:
  47.     if (eatname == item['name']):
  48.         print(' - '.join([item['brand'], str(item['cost'])]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement