Advertisement
kostovhg

Star Enigma of Tuleshkova

Aug 1st, 2021
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. import re
  2.  
  3. number_of_lines = int(input())
  4. pattern = r"[starSTAR]"
  5. pattern_2 = r"([^\@\-\!\:\>]*?)@(?P<planet_name>[a-zA-Z]+)([^\@\-\!\:\>]*?)\:(?P<population>\d+)([^\@\-\!\:\>]*?)!(?P<attack_type>[AD])!([^\@\-\!\:\>]*?)\-\>(?P<soldier_count>\d+)"
  6. attacked_planets = []
  7. destroyed_planets = []
  8.  
  9. for line in range(number_of_lines):
  10.     text = input()
  11.     decrypted_message = ""
  12.     key = len(re.findall(pattern, text))
  13.     for char in text:
  14.         decrypted_message += chr(ord(char) - key)
  15.     derived_info_iter = re.finditer(pattern_2, decrypted_message)
  16.     for info in derived_info_iter:
  17.         planet_name = info.group("planet_name")
  18.         attack_type = info.group("attack_type")
  19.         if attack_type == "A":
  20.             if planet_name not in attacked_planets:
  21.                 attacked_planets.append(planet_name)
  22.         else:
  23.             if planet_name not in destroyed_planets:
  24.                 destroyed_planets.append(planet_name)
  25.  
  26. print(f"Attacked planets: {len(attacked_planets)}")
  27. for attacked_planet in sorted(attacked_planets):
  28.     print(f"-> {attacked_planet}")
  29.  
  30. print(f"Destroyed planets: {len(destroyed_planets)}")
  31. for destroyed_planet in sorted(destroyed_planets):
  32.     print(f"-> {destroyed_planet}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement