Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- pattern_decrypt = r"[STARstar]"
- pattern_text = r"@([A-Z]*[a-z]+)[^@\-!:>]*:(\d+)[^@\-:>]*!(A|D)![^@!:\->]*->(\d+)"
- attacked = []
- destroyed = []
- number = int(input())
- for _ in range(number):
- decrypted = ""
- text = input()
- matches_count = len(re.findall(pattern_decrypt, text))
- for s in text:
- new_s = ord(s) - matches_count
- decrypted += chr(new_s)
- matches = re.finditer(pattern_text, decrypted)
- for match in matches:
- if match.group(1) and match.group(2) and match.group(3) and match.group(4):
- planet = match.group(1)
- attack_type = match.group(3)
- if attack_type == "A":
- attacked.append(planet)
- elif attack_type == "D":
- destroyed.append(planet)
- print(f"Attacked planets: {len(attacked)}")
- if len(attacked) > 0:
- for planet_ in sorted(attacked):
- print(f"-> {planet_}")
- print(f"Destroyed planets: {len(destroyed)}")
- if len(destroyed) > 0:
- for planet_ in sorted(destroyed):
- print(f"-> {planet_}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement