Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- # Read user input
- armor_values = deque(int(num) for num in input().split(","))
- strike_values = [int(num) for num in input().split(",")]
- killed_monsters = 0
- # Logic
- while armor_values and strike_values:
- curr_armor = armor_values.popleft()
- curr_strike = strike_values.pop()
- if curr_strike >= curr_armor: # The monster is killed
- remaining_strike = curr_strike - curr_armor
- killed_monsters += 1
- if strike_values:
- strike_values[-1] += remaining_strike
- elif not strike_values and remaining_strike > 0:
- strike_values.append(remaining_strike)
- else: # The monster survives
- curr_armor -= curr_strike
- armor_values.append(curr_armor)
- # Print output
- if not armor_values:
- print("All monsters have been killed!")
- if not strike_values:
- print("The soldier has been defeated.")
- print(f"Total monsters killed: {killed_monsters}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement