Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def shifttext(inp: str, shift: int):
- data = []
- for i in inp:
- data.append(chr(ord(i) - shift))
- output = ''.join(data)
- return output
- star = re.compile(r"[star]", re.I)
- msg = re.compile(r"""([^\@\-\!\:\>]*?) # group for any character except @, -, !, :, >
- @(?P<planet>[A-Za-z]+) # that should be the planet name
- ([^\@\-\!\:\>]*?) # first group
- \:\d+ # any digits starting with :
- ([^\@\-\!\:\>]*?) # first group
- \!(?P<type>[AD])\! # Type, A or D
- ([^\@\-\!\:\>]*?) # first group
- \-\>\d+""", re.X) # digits after ->
- planets = {'Attacked': [], 'Destroyed': []}
- count = int(input())
- for _ in range(count):
- encrypted = input()
- shift = len(re.findall(star, encrypted))
- decrypted = shifttext(encrypted, shift)
- m = re.search(msg, decrypted)
- if m:
- planet = m.group('planet')
- t = m.group('type')
- if t == 'A':
- planets['Attacked'].append(planet)
- else:
- planets['Destroyed'].append(planet)
- for t in planets:
- ps = sorted(planets[t])
- print(f"{t} planets: {len(ps)}")
- [print(f"-> {p}") for p in ps]
Add Comment
Please, Sign In to add comment