Yanam

trojan_invasion

Feb 15th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. waves = int(input())
  2. plates = list(map(int, input().split()))
  3. attack = 0
  4. while plates:
  5.     if waves == 0:
  6.         break
  7.     wave = list(map(int, input().split()))
  8.     waves -= 1
  9.     attack += 1
  10.     if attack == 3:
  11.         plates.append(int(input()))
  12.         attack = 0
  13.     while wave:
  14.         if len(plates) == 0:
  15.             break
  16.         if wave[-1] > plates[0]:
  17.             wave[-1] -= plates[0]
  18.             plates.pop(0)
  19.         elif wave[-1] < plates[0]:
  20.             plates[0] -= wave[-1]
  21.             wave.pop()
  22.         elif wave[-1] == plates[0]:
  23.             wave.pop()
  24.             plates.pop(0)
  25. if plates:
  26.     print('The Spartans successfully repulsed the Trojan attack.')
  27.     print(f"Plates left: {', '.join(map(str, plates))}")
  28.  
  29. elif wave:
  30.     print('The Trojans successfully destroyed the Spartan defense.')
  31.     print(f"Warriors left: {', '.join(reversed([str(x) for x in wave]))}")
Advertisement
Add Comment
Please, Sign In to add comment