SimeonTs

SUPyF2 P.-Mid-Exam/10 March 2019/2 - 02. Seize the Fire

Oct 29th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.78 KB | None | 0 0
  1. """
  2. Technology Fundamentals Mid Exam - 10 March 2019 Group 2
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1555#1
  4.  
  5. SUPyF2 P.-Mid-Exam/10 March 2019/2 - 02. Seize the Fire
  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",
  11. based on the given information 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. "{typeOfFire} = {valueOfCell}#{typeOfFire} = {valueOfCell}#{typeOfFire} = {valueOfCell}……"
  15. Afterwards you will receive the amount of water you have for putting out the fires.
  16. There is a range of fire for each of the fire types,
  17. and if a cell’s value is below or exceeds it, it is invalid and you don’t need to put it out.
  18. Type of Fire    Range
  19. High    81 - 125
  20. Medium  51 - 80
  21. Low 1 - 50
  22. If a cell is valid, you have to put it out by reducing the water with its value.
  23. Putting out fire also takes effort and you need to calculate it.
  24. Its value is equal to 25% of the cell’s value. In the end you will have to print the total effort.
  25. 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.
  27. In the end, 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:
  36.    "Total Fire: {totalFire}"
  37. Input / Constraints
  38. • On the 1st line you are going to receive the fires with their cells in the format described above –
  39. integer numbers in the range [1…500]
  40. • On the 2nd line, you are going to be given the water – an integer number in the range [0….100000]
  41. Output
  42. • Print the cells, which you have put out in the following format:
  43. "Cells:
  44. - {cell}
  45. - {cell2}
  46. - {cell3}
  47. - {cell5}
  48. ……
  49. - {cellN}"
  50. • Print the effort, rounded 2 digits after the decimal separator in the following format:
  51. "Effort: {effort}"
  52. • Print the total fire put out
  53. "Total Fire: {totalFire}"
  54.  
  55. Examples:
  56. Input:
  57. High = 89#Low = 28#Medium = 77#Low = 23
  58. 1250
  59.  
  60. Output:
  61. High = 89#Low = 28#Medium = 77#Low = 23
  62. 1250
  63.  
  64. Comments:
  65. After reading the output, we start checking the level of the fire and its validity.
  66. The first is valid, so we subtract the 89 from the amount of water – 1250, and the water becomes 1161.
  67. We need to calculate the effort, which is 25% of 89. We will add 89 to the total fire we have put out.
  68. In the end the effort is 54.22 and the total fire: 217
  69.  
  70. Input:
  71. High = 150#Low = 55#Medium = 86#Low = 40#High = 110#Medium = 77
  72. 220
  73.  
  74. Output:
  75. Cells:
  76. - 40
  77. - 110
  78. Effort: 37.50
  79. Total Fire: 150
  80. """
  81. all_cells = input().split("#")
  82. water = int(input())
  83. effort = 0
  84. total_fire = 0
  85. valid_cells = []
  86.  
  87. for cell in all_cells:
  88.     value_of_cell, type_of_fire = cell.split(" = ")
  89.     type_of_fire = int(type_of_fire)
  90.     if (value_of_cell == "High" and (81 <= type_of_fire <= 125)) or \
  91.             (value_of_cell == "Medium" and (51 <= type_of_fire <= 80)) or \
  92.             (value_of_cell == "Low" and (1 <= type_of_fire <= 50)):
  93.         if water - type_of_fire >= 0:
  94.             water -= type_of_fire
  95.             effort += type_of_fire * 0.25
  96.             total_fire += type_of_fire
  97.             valid_cells += [type_of_fire]
  98.  
  99. print(f"Cells:")
  100. for cell in valid_cells:
  101.     print(f" - {cell}")
  102. print(f"Effort: {effort:.2f}")
  103. print(f"Total Fire: {total_fire}")
Add Comment
Please, Sign In to add comment