Sichanov

Star Enigma

Nov 22nd, 2021
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 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]+)([^@:!>-]+)?:(?P<population>\d+)([^@:!>-]+)?\!(?P<type>(A|D))\!([^@:!>-]+)?\->(?P<soldier>\d+)([^@:!>-]+)"
  13.     pattern = r"([^@!:>-]+)?@(?P<planet>[A-Za-z]+)([^@!:>-]+)?:([^@!:>-]+)?(?P<population>\d+)([^@!:>-]+)?!([^@!:>-]+)?(?P<type>[AD])([^@!:>-]+)?!([^@!:>-]+)?->([^@!:>-]+)?(?P<soldier>\d+)([^@!:>-]+)?"
  14.     matches = re.finditer(pattern, decrypted)
  15.     for match in matches:
  16.         current = match.groupdict()
  17.         if current['type'] == 'A':
  18.             attacked.append(current['planet'])
  19.         else:
  20.             destroyed.append(current['planet'])
  21.  
  22. print('Attacked planets: ' + str(len(attacked)))
  23. for i in sorted(attacked):
  24.     print(f'-> {i}')
  25. print('Destroyed planets: ' + str(len(destroyed)))
  26. for i in sorted(destroyed):
  27.     print(f'-> {i}')
  28.  
Advertisement
Add Comment
Please, Sign In to add comment