Sichanov

Star Enigma

Nov 18th, 2021
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import re
  2.  
  3. number_of_messages = int(input())
  4. attacked = []
  5. destroyed = []
  6. for i in range(number_of_messages):
  7.     message = input()
  8.     count = len(re.findall('[SsTtAaRr]', message))
  9.     decrypted = ''
  10.     for letter in message:
  11.         decrypted += chr(ord(letter) - count)
  12.     pattern = r"@(?P<planet>[A-Za-z\s]+)([^@!:>-]+)?:([^@!:>\d+-]+)?(?P<population>\d+)([^@!:>\d+-]+)?!([^@!:>A|D+-]+)?(?P<type>[AD])([^@!:>AD+-]+)?!([^@!:>AD+-]+)?->([^@!:>\d+-]+)?(?P<soldier>\d+)"
  13.     matches = re.finditer(pattern, decrypted)
  14.     for match in matches:
  15.         current = match.groupdict()
  16.         if current['type'] == 'A':
  17.             attacked.append(current['planet'])
  18.         else:
  19.             destroyed.append(current['planet'])
  20.  
  21. print('Attacked planets: ' + str(len(attacked)))
  22. for i in sorted(attacked):
  23.     print(f'-> {i}')
  24. print('Destroyed planets: ' + str(len(destroyed)))
  25. for i in sorted(destroyed):
  26.     print(f'-> {i}')
Advertisement
Add Comment
Please, Sign In to add comment