Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- number_of_messages = int(input())
- attacked = []
- destroyed = []
- for i in range(number_of_messages):
- message = input()
- count = len(re.findall('[SsTtAaRr]', message))
- decrypted = ''
- for letter in message:
- decrypted += chr(ord(letter) - count)
- pattern = r"@(?P<planet>[A-Za-z\s]+)([^@!:>-]+)?:([^@!:>\d+-]+)?(?P<population>\d+)([^@!:>\d+-]+)?!([^@!:>A|D+-]+)?(?P<type>[AD])([^@!:>AD+-]+)?!([^@!:>AD+-]+)?->([^@!:>\d+-]+)?(?P<soldier>\d+)"
- matches = re.finditer(pattern, decrypted)
- for match in matches:
- current = match.groupdict()
- if current['type'] == 'A':
- attacked.append(current['planet'])
- else:
- destroyed.append(current['planet'])
- print('Attacked planets: ' + str(len(attacked)))
- for i in sorted(attacked):
- print(f'-> {i}')
- print('Destroyed planets: ' + str(len(destroyed)))
- for i in sorted(destroyed):
- print(f'-> {i}')
Advertisement
Add Comment
Please, Sign In to add comment