Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Time: 0.050 s """
- from collections import defaultdict
- # import sys
- def add_city(city_name, population, gold, cities):
- cities[city_name]['population'] += population
- cities[city_name]['gold'] += gold
- def plunder_city(city_name, people, gold, cities):
- print(f"{city_name} plundered! {gold} gold stolen, {people} citizens killed.")
- cities[city_name]['population'] -= people
- cities[city_name]['gold'] -= gold
- if cities[city_name]['population'] <= 0 or cities[city_name]['gold'] <= 0:
- print(f"{city_name} has been wiped off the map!")
- cities.pop(city_name)
- def prosper_city(city_name, gold, cities):
- if gold < 0:
- print(f"Gold added cannot be a negative number!")
- else:
- cities[city_name]['gold'] += gold
- print(f"{gold} gold added to the city treasury. {city_name} now has {cities[city_name]['gold']} gold.")
- def process_commands(command, cities):
- action, city_name = command.split('=>')[0], command.split('=>')[1]
- if action == "Plunder":
- people, gold = map(int, command.split('=>')[2:])
- plunder_city(city_name, people, gold, cities)
- elif action == "Prosper":
- gold = int(command.split('=>')[2])
- prosper_city(city_name, gold, cities)
- cities = defaultdict(lambda: {'population': 0, 'gold': 0})
- info = input() # sys.stdin.readline().strip()
- while info != "Sail":
- city_name, population, gold = info.split("||")
- add_city(city_name, int(population), int(gold), cities)
- info = input() # sys.stdin.readline().strip()
- command = input() # sys.stdin.readline().strip()
- while command != "End":
- process_commands(command, cities)
- command = input() # sys.stdin.readline().strip()
- if cities:
- print(f"Ahoy, Captain! There are {len(cities)} wealthy settlements to go to:")
- for city, city_info in cities.items():
- print(f"{city} -> Population: {city_info['population']} citizens, Gold: {city_info['gold']} kg")
- else:
- print(f"Ahoy, Captain! All targets have been plundered and destroyed!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement