Advertisement
Maxim_01

Untitled

Jun 25th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. data = list(map(int, input().split(' ')))
  2.  
  3. def shoot_func(index, power, targets):
  4.     if 0 <= index < len(targets):
  5.         if targets[index] - power <= 0:
  6.             targets.pop(index)
  7.         else:
  8.             targets[index] -= power
  9.     return targets
  10. def add_func(index, value, targets):
  11.     if 0 <= index < len(targets):
  12.         targets.insert(index, value)
  13.     else:
  14.         print("Invalid placement!")
  15.     return targets
  16. def strike_func(index, radius, targets):
  17.     start_index = index - radius
  18.     final_index = index + radius
  19.     if start_index >= 0 and final_index < len(targets):
  20.         targets = [targets[i] for i in range(len(targets)) if i < start_index or i > final_index]
  21.     else:
  22.         print("Strike missed!")
  23.     return targets
  24. def moving_targets(targets):
  25.     while True:
  26.         command = input()
  27.         if command == "End":
  28.             return ("|").join(str(s) for s in targets)
  29.         command = command.split(" ")
  30.         current_command = command[0]
  31.         first_element = int(command[1])
  32.         second_element = int(command[2])
  33.         if current_command == "Shoot":
  34.             targets = shoot_func(first_element, second_element, targets)
  35.         elif current_command == 'Add':
  36.             targets = add_func(first_element, second_element, targets)
  37.         elif current_command == "Strike":
  38.             targets = strike_func(first_element, second_element, targets)
  39.  
  40. print(moving_targets(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement