SimeonTs

SUPyF2 Lists Basics Exercise - 08. Seize the Fire

Oct 3rd, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.80 KB | None | 0 0
  1. """
  2. Lists Basics - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1725#7
  4.  
  5. SUPyF2 Lists Basics Exercise - 08. Seize the Fire (not included in final score)
  6.  
  7. Problem:
  8. The group of adventurists have gone on their first task. Now they have to walk through fire - literally.
  9. They have to use all of the water they have left. Your task is to help them survive.
  10. Create a program that calculates the water that is needed to put out a "fire cell", based on the given information
  11. about its "fire level" and how much it gets affected by water.
  12. First, you will be given the level of fire inside the cell with the integer value of the cell,
  13. which represents the needed water to put out the fire.  They will be given in the following format:
  14.  
  15. "{typeOfFire} = {valueOfCell}#{typeOfFire} = {valueOfCell}#{typeOfFire} = {valueOfCell}……"
  16. Afterwards you will receive the amount of water you have for putting out the fires.
  17. There is a range of fire for each of the fire types, and if a cell’s value is below or exceeds it,
  18. it is invalid and you don’t need to put it out.
  19. Type of Fire    Range
  20. High    81 - 125
  21. Medium  51 - 80
  22. Low 1 - 50
  23. If a cell is valid, you have to put it out by reducing the water with its value.
  24. Putting out fire also takes effort and you need to calculate it. Its value is equal to 25% of the cell’s value.
  25. In the end you will have to print the total effort. Keep putting out cells until you run out of water.
  26. If you don’t have enough water to put out a given cell – skip it and try the next one. In the end,
  27. print the cells you have put out in the following format:
  28. "Cells:
  29. - {cell1}
  30. - {cell2}
  31. - {cell3}
  32. ……
  33. - {cellN}"
  34. "Effort: {effort}"
  35. In the end, print the total fire you have put out from all of the cells in the following format: "Total Fire: {totalFire}"
  36. Input / Constraints
  37. • On the 1st line you are going to receive the fires with their cells in the format described above –
  38. integer numbers in the range [1…500]
  39. • On the 2nd line, you are going to be given the water – an integer number in the range [0….100000]
  40. Output
  41. • Print the cells, which you have put out in the following format:
  42. "Cells:
  43. - {cell}
  44. - {cell2}
  45. - {cell3}
  46. - {cell5}
  47. ……
  48. - {cellN}"
  49. • Print the effort, rounded 2 digits after the decimal separator in the following format:
  50. "Effort: {effort}"
  51. • Print the total fire put out
  52. "Total Fire: {totalFire}"
  53.  
  54. Examples:
  55. Input:
  56. High = 89#Meduim = 53#Low = 28#Medium = 77#Low = 23
  57. 1250
  58.  
  59. Output:
  60. Cells:
  61. - 89
  62. - 28
  63. - 77
  64. - 23
  65. Effort: 54.25
  66. Total Fire: 217
  67.  
  68. Comments:
  69. After reading the output, we start checking the level of the fire and its validity.
  70. The first is valid, so we subtract the 89 from the amount of water – 1250, and the water becomes 1161.
  71. We need to calculate the effort, which is 25% of 89. We will add 89 to the total fire we have put out.
  72. In the end the effort is 54.22 and the total fire: 217
  73.  
  74. Input:
  75. High = 150#Low = 55#Medium = 86#Low = 40#High = 110#Medium = 77
  76. 220
  77.  
  78. Output:
  79. Cells:
  80. - 40
  81. - 110
  82. Effort: 37.50
  83. Total Fire: 150
  84. """
  85. all_cells = input().split("#")
  86. water = int(input())
  87. effort = 0
  88. total_fire = 0
  89. valid_cells = []
  90.  
  91. for cell in all_cells:
  92.     value_of_cell, type_of_fire = cell.split(" = ")
  93.     type_of_fire = int(type_of_fire)
  94.     if (value_of_cell == "High" and (81 <= type_of_fire <= 125)) or \
  95.             (value_of_cell == "Medium" and (51 <= type_of_fire <= 80)) or \
  96.             (value_of_cell == "Low" and (1 <= type_of_fire <= 50)):
  97.         if water - type_of_fire >= 0:
  98.             water -= type_of_fire
  99.             effort += type_of_fire * 0.25
  100.             total_fire += type_of_fire
  101.             valid_cells += [type_of_fire]
  102.  
  103. print(f"Cells:")
  104. for cell in valid_cells:
  105.     print(f" - {cell}")
  106. print(f"Effort: {effort:.2f}")
  107. print(f"Total Fire: {total_fire}")
Add Comment
Please, Sign In to add comment