Advertisement
mbratanov

01. Monster Extermination

Oct 16th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. from collections import deque
  2.  
  3. # Read user input
  4. armor_values = deque(int(num) for num in input().split(","))
  5. strike_values = [int(num) for num in input().split(",")]
  6. killed_monsters = 0
  7.  
  8. # Logic
  9. while armor_values and strike_values:
  10.     curr_armor = armor_values.popleft()
  11.     curr_strike = strike_values.pop()
  12.  
  13.     if curr_strike >= curr_armor:  # The monster is killed
  14.         remaining_strike = curr_strike - curr_armor
  15.         killed_monsters += 1
  16.         if strike_values:
  17.             strike_values[-1] += remaining_strike
  18.         elif not strike_values and remaining_strike > 0:
  19.             strike_values.append(remaining_strike)
  20.  
  21.     else:  # The monster survives
  22.         curr_armor -= curr_strike
  23.         armor_values.append(curr_armor)
  24.  
  25. # Print output
  26. if not armor_values:
  27.     print("All monsters have been killed!")
  28. if not strike_values:
  29.     print("The soldier has been defeated.")
  30.  
  31. print(f"Total monsters killed: {killed_monsters}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement