Advertisement
pacho_the_python

Untitled

Mar 22nd, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. import re
  2.  
  3. num = int(input())
  4.  
  5. attacked_planets = []
  6. destroyed_planets = []
  7. attack_counter = 0
  8. destroy_counter = 0
  9.  
  10. for i in range(num):
  11.     message = input()
  12.     key = [message.count(x) for x in message if x in "satrSTAR"]
  13.  
  14.     decoded_message = ("".join([chr(ord(letter) - len(key)) for letter in message]))
  15.  
  16.     pattern = r"@([A-Z][a-z]+):(\d+)\!([AD])\!->(\d+)"
  17.     result = re.findall(pattern, decoded_message)
  18.     if result:
  19.         for j in result:
  20.             planet = j[0]
  21.             population = int(j[1])
  22.             attack_type = j[2]
  23.             if attack_type == "A":
  24.                 attacked_planets.append(planet)
  25.                 attack_counter += 1
  26.             elif attack_type == "D":
  27.                 destroyed_planets.append(planet)
  28.                 destroy_counter += 1
  29.             soldiers = j[3]
  30.  
  31. print(f"Attacked planets: {attack_counter}")
  32.  
  33. for k in sorted(attacked_planets):
  34.     print(f"-> {k}")
  35.  
  36. print(f"Destroyed planets: {destroy_counter}")
  37.  
  38. for y in sorted(destroyed_planets):
  39.     print(f"-> {y}")
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement