Advertisement
Guest User

03. Moving Target

a guest
Jul 2nd, 2020
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. targets_sequence = [int(x) for x in input().split(' ')]
  2.  
  3. while True:
  4.     tokens = input().split(' ')
  5.     command = tokens[0]
  6.     index = 0
  7.     value = 0
  8.  
  9.     if command == "Shoot":
  10.         index = int(tokens[1])
  11.         value = int(tokens[2])
  12.  
  13.         if index < len(targets_sequence):
  14.             targets_sequence[index] -= value
  15.  
  16.             if targets_sequence[index] <= 0:
  17.                 targets_sequence.pop(index)
  18.  
  19.     elif command == "Add":
  20.         index = int(tokens[1])
  21.         value = int(tokens[2])
  22.  
  23.         if index < len(targets_sequence):
  24.             targets_sequence.insert(index, value)
  25.         else:
  26.             print("Invalid placement!")
  27.  
  28.     elif command == "Strike":
  29.         index = int(tokens[1])
  30.         radius = int(tokens[2])
  31.  
  32.         start = index - radius
  33.         end = index + radius
  34.  
  35.         new_targets_sequence = []
  36.  
  37.         if start >= 0 and end < len(targets_sequence):
  38.             strike = targets_sequence[start:end + 1]
  39.             new_targets_sequence = [x for x in targets_sequence if x not in strike]
  40.             targets_sequence = new_targets_sequence
  41.         else:
  42.             print("Strike missed!")
  43.  
  44.     elif command == "End":
  45.         targets_sequence = [str(x) for x in targets_sequence]
  46.         print("|".join(targets_sequence))
  47.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement