Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- num = int(input())
- attacked_planets = []
- destroyed_planets = []
- attack_counter = 0
- destroy_counter = 0
- for i in range(num):
- message = input()
- key = [message.count(x) for x in message if x in "satrSTAR"]
- decoded_message = ("".join([chr(ord(letter) - len(key)) for letter in message]))
- pattern = r"@([A-Z][a-z]+):(\d+)\!([AD])\!->(\d+)"
- result = re.findall(pattern, decoded_message)
- if result:
- for j in result:
- planet = j[0]
- population = int(j[1])
- attack_type = j[2]
- if attack_type == "A":
- attacked_planets.append(planet)
- attack_counter += 1
- elif attack_type == "D":
- destroyed_planets.append(planet)
- destroy_counter += 1
- soldiers = j[3]
- print(f"Attacked planets: {attack_counter}")
- for k in sorted(attacked_planets):
- print(f"-> {k}")
- print(f"Destroyed planets: {destroy_counter}")
- for y in sorted(destroyed_planets):
- print(f"-> {y}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement