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]+)([^@:!>-]+)?:(?P<population>\d+)([^@:!>-]+)?\!(?P<type>(A|D))\!([^@:!>-]+)?\->(?P<soldier>\d+)([^@:!>-]+)"
- pattern = r"([^@!:>-]+)?@(?P<planet>[A-Za-z]+)([^@!:>-]+)?:([^@!:>-]+)?(?P<population>\d+)([^@!:>-]+)?!([^@!:>-]+)?(?P<type>[AD])([^@!:>-]+)?!([^@!:>-]+)?->([^@!:>-]+)?(?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