Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. waves = int(input())
  5. plates = deque([int(x) for x in input().split(' ')])
  6. warriors = []
  7.  
  8. for i in range(1, waves + 1):
  9.     power = input().split(' ')
  10.     if plates:
  11.         [warriors.append(int(x)) for x in power]
  12.     if i % 3 == 0:
  13.         new_plate = int(input())
  14.         plates.append(new_plate)
  15.     while True:
  16.         if not warriors or not plates:
  17.             break
  18.         current_plate = plates.popleft()
  19.         while current_plate > 0:
  20.             if warriors:
  21.                 current_warrior = warriors.pop()
  22.             else:
  23.                 plates.appendleft(current_plate)
  24.                 break
  25.             if current_plate > current_warrior:
  26.                 current_plate -= current_warrior
  27.             elif current_plate < current_warrior:
  28.                 current_plate -= current_warrior
  29.                 warriors.append(abs(current_plate))
  30.             else:
  31.                 current_plate -= current_warrior
  32.  
  33. if not plates:
  34.     print('The Trojans successfully destroyed the Spartan defense.')
  35.     if warriors:
  36.         print(f"Warriors left: {', '.join(map(str, reversed(warriors)))}")
  37. else:
  38.     print('The Spartans successfully repulsed the Trojan attack.')
  39.     print(f"Plates left: {', '.join(map(str, plates))}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement