Advertisement
viligen

star_enigma

Nov 18th, 2021
1,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import re
  2.  
  3. pattern_decrypt = r"[STARstar]"
  4. pattern_text = r"@([A-Z]*[a-z]+)[^@\-!:>]*:(\d+)[^@\-:>]*!(A|D)![^@!:\->]*->(\d+)"
  5. attacked = []
  6. destroyed = []
  7. number = int(input())
  8. for _ in range(number):
  9.     decrypted = ""
  10.     text = input()
  11.     matches_count = len(re.findall(pattern_decrypt, text))
  12.     for s in text:
  13.         new_s = ord(s) - matches_count
  14.         decrypted += chr(new_s)
  15.  
  16.     matches = re.finditer(pattern_text, decrypted)
  17.     for match in matches:
  18.         if match.group(1) and match.group(2) and match.group(3) and match.group(4):
  19.             planet = match.group(1)
  20.             attack_type = match.group(3)
  21.             if attack_type == "A":
  22.                 attacked.append(planet)
  23.             elif attack_type == "D":
  24.                 destroyed.append(planet)
  25.  
  26. print(f"Attacked planets: {len(attacked)}")
  27. if len(attacked) > 0:
  28.     for planet_ in sorted(attacked):
  29.         print(f"-> {planet_}")
  30.  
  31. print(f"Destroyed planets: {len(destroyed)}")
  32. if len(destroyed) > 0:
  33.     for planet_ in sorted(destroyed):
  34.         print(f"-> {planet_}")
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement