Advertisement
Guest User

Untitled

a guest
May 26th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 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. # rows = [
  14. # "АстроЕда (150 г): Борщ - 200, Крем-суп грибной - 185",
  15. # "Космопит (300 г): Торт Москва - 410, Борщ - 450"
  16. # ]
  17.  
  18. # rows = [
  19. # "АстроЕда (115 г): Борщ - 310, Мясо с гречкой - 300, Суп гороховый - 280",
  20. # "Космопит (165 г): Суп гороховый - 400, Борщ - 420, Мясо с гречкой - 410",
  21. # "Астро-Гастро (200 г): Мясо с гречкой - 450, Крем-суп грибной - 400",
  22. # "Обед в космосе (95 г): Мясо с гречкой - 250, Борщ - 195, Суп гороховый - 200"
  23. # ]
  24.  
  25.  
  26. items = []
  27. global_eats = {}
  28. minimums = {}
  29. for row in rows:
  30. brandAndWeight, eats = row.split(': ')
  31. brand, weight = brandAndWeight.split(' (')
  32. weight = weight.replace(' г)', '')
  33. eats = eats.split(', ')
  34. for eat in eats:
  35. name, price = eat.split(' - ')
  36. cost = math.ceil(300 / int(weight)) * int(price)
  37. items.append({
  38. 'brand': brand,
  39. 'name': name,
  40. 'price': price,
  41. 'cost': cost,
  42. 'weight': math.ceil(300 / int(weight)) * int(weight)
  43. })
  44.  
  45. if name in global_eats:
  46. global_eats[name] += cost
  47. else:
  48. global_eats[name] = cost
  49.  
  50. if name in minimums:
  51. if int(minimums[name]) > int(price):
  52. minimums[name] = price
  53. else:
  54. minimums[name] = price
  55.  
  56. global_eats = sorted(global_eats.items(), key = lambda i: i[1])
  57. minimums = sorted(minimums.items(), key = lambda i: i[1])
  58. minimums.reverse()
  59. # print(minimums)
  60.  
  61. items = sorted(items, key=lambda i: i['cost'])
  62. items.reverse()
  63. brandname = ''
  64. # eatname = global_eats[0][0]
  65. eatname = minimums[1][0]
  66.  
  67. print(eatname + ':')
  68.  
  69. for item in items:
  70. if (eatname == item['name']):
  71. print(' - '.join([item['brand'], str(item['cost'])]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement