Spocoman

03. Logistics

Dec 26th, 2021 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. cargo_count = int(input())
  2. bus = 0
  3. truck = 0
  4. train = 0
  5.  
  6. for i in range(cargo_count):
  7.     cargo = float(input())
  8.     if cargo < 4:
  9.         bus += cargo
  10.     elif cargo < 12:
  11.         truck += cargo
  12.     else:
  13.         train += cargo
  14.  
  15. total = bus + truck + train
  16. average = (bus * 200 + truck * 175 + train * 120) / total
  17. print(f'{average:.2f}')
  18. print(f'{bus / total * 100:.2f}%')
  19. print(f'{truck / total * 100:.2f}%')
  20. print(f'{train / total * 100:.2f}%')
  21.  
  22.  
  23. Тарикатско решение:
  24.  
  25. cargo_count = int(input())
  26. bus = 0
  27. truck = 0
  28. train = 0
  29.  
  30. for i in range(cargo_count):
  31.     cargo = float(input())
  32.     if cargo < 4:
  33.         bus += cargo
  34.     elif cargo < 12:
  35.         truck += cargo
  36.     else:
  37.         train += cargo
  38.  
  39. print(f'{(bus * 200 + truck * 175 + train * 120) / (bus + truck + train):.2f}')
  40.  
  41. for i in [bus, truck, train]:
  42.     print(f'{i / (bus + truck + train) * 100:.2f}%')
  43.  
  44.  
  45.  
  46. Фундаменталс решение:
  47.  
  48. cargo_count = int(input())
  49. total = {'bus': 0, 'truck': 0, 'train': 0}
  50.  
  51. for i in range(0, cargo_count):
  52.     cargo = float(input())
  53.     total[{cargo >= 12: 'train', cargo < 12: 'truck', cargo < 4: 'bus'}[True]] += cargo
  54.  
  55. average = (total['bus'] * 200 + total['truck'] * 175 + total['train'] * 120) / sum(total.values())
  56. print(f'{average:.2f}')
  57.  
  58. for i in ['bus', 'truck', 'train']:
  59.     print(f'{total[i] / sum(total.values()) * 100:.2f}%')
  60.  
Add Comment
Please, Sign In to add comment