Advertisement
Guest User

Untitled

a guest
Nov 20th, 2021
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import re
  2.  
  3. number_of_messages = int(input())
  4. attacked_planets = []
  5. destroyed_planets = []
  6.  
  7. for message in range(number_of_messages):
  8.     encrypted_message = input()
  9.     decrypted_message = ''
  10.  
  11.     pattern = r'[starSTAR]'
  12.     matches = len(re.findall(pattern, encrypted_message))
  13.  
  14.     for character in encrypted_message:
  15.         decrypted_character = chr((ord(character)) - matches)
  16.         decrypted_message += decrypted_character
  17.  
  18.     planets_pattern = r'@(?P<planet>[A-Z][a-z]+)[^\@\-\!\:\>]?:(?P<population>\d+)[^\@\-\!\:\>]?\!(?P<attack_type>A|D)\![^\@\-\!\:\>]?->(?P<soldiers>\d+)'
  19.     planet_matches = re.finditer(planets_pattern, decrypted_message)
  20.     for value in planet_matches:
  21.         planet, attack_type = value.group('planet'), value.group('attack_type')
  22.  
  23.         if attack_type == 'A':
  24.             attacked_planets.append(planet)
  25.         else:
  26.             destroyed_planets.append(planet)
  27.  
  28. print(f'Attacked planets: {len(attacked_planets)}')
  29. for planet in sorted(attacked_planets):
  30.     print(f'-> {planet}')
  31.  
  32. print(f'Destroyed planets: {len(destroyed_planets)}')
  33. for planet in sorted(destroyed_planets):
  34.     print(f'-> {planet}')
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement