Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 03. MOBA Challenger 90/100 ! (Test 10 Runtime error)
- # Dictionaries - More Exercises
- # https://judge.softuni.org/Contests/Practice/Index/1738#2
- def is_players_valid(some_dict: dict, player_one: str, player_two: str):
- if player_one and player_two in some_dict.keys():
- return True
- return False
- def calculate_total_skill_points(some_dict: dict):
- total_skill_points = {}
- for current_name, skills in some_dict.items():
- for current_position, skill_point in skills.items():
- current_skill_points = int(skill_point)
- if current_name not in total_skill_points:
- total_skill_points[current_name] = current_skill_points
- else:
- total_skill_points[current_name] += current_skill_points
- return total_skill_points
- def time_for_duel(some_dict: dict, player_one, player_two):
- player1_common = []
- player2_common = []
- for key1, skills1 in some_dict[player_one].items():
- if key1 not in player1_common:
- player1_common.append(key1)
- for key2, skills2 in some_dict[player_two].items():
- if key2 not in player2_common:
- player2_common.append(key2)
- for el in player1_common:
- if el in player2_common:
- if some_dict[player_one][el] > some_dict[player_two][el]:
- del some_dict[player_two]
- del total_skills_points[player_two]
- else:
- del some_dict[player_one]
- del total_skills_points[player_one]
- return some_dict
- data = input()
- my_dict = {}
- total_skills_points = {}
- while not data == 'Season end':
- if ' -> ' in data:
- details = data.split(" -> ")
- player = details[0]
- position = details[1]
- skill_points = int(details[2])
- if player not in my_dict.keys():
- my_dict[player] = {position: skill_points}
- else:
- if position not in my_dict[player]:
- my_dict[player].update({position: skill_points})
- else:
- old_score = my_dict[player][position]
- my_dict[player].update({position: max(skill_points, old_score)})
- elif ' vs ' in data:
- details = data.split(' vs ')
- player1 = details[0]
- player2 = details[1]
- if is_players_valid(my_dict, player1, player2):
- my_dict = time_for_duel(my_dict, player1, player2)
- total_skills_points = (calculate_total_skill_points(my_dict))
- data = input()
- for name, points in sorted(total_skills_points.items(), key=lambda kv: (-kv[1], kv[0])):
- print(f'{name}: {points} skill')
- for name1, points1 in sorted(my_dict[name].items(), key=lambda kv: (-kv[1], kv[0])):
- print(f'- {name1} <::> {points1}')
Add Comment
Please, Sign In to add comment