GeorgiLukanov87

03. MOBA Challenger 90/100

Jul 20th, 2022 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.76 KB | None | 0 0
  1. # 03. MOBA Challenger 90/100 ! (Test 10 Runtime error)
  2. # Dictionaries - More Exercises
  3. # https://judge.softuni.org/Contests/Practice/Index/1738#2
  4.  
  5. def is_players_valid(some_dict: dict, player_one: str, player_two: str):
  6.     if player_one and player_two in some_dict.keys():
  7.         return True
  8.     return False
  9.  
  10.  
  11. def calculate_total_skill_points(some_dict: dict):
  12.     total_skill_points = {}
  13.     for current_name, skills in some_dict.items():
  14.         for current_position, skill_point in skills.items():
  15.             current_skill_points = int(skill_point)
  16.             if current_name not in total_skill_points:
  17.                 total_skill_points[current_name] = current_skill_points
  18.             else:
  19.                 total_skill_points[current_name] += current_skill_points
  20.     return total_skill_points
  21.  
  22.  
  23. def time_for_duel(some_dict: dict, player_one, player_two):
  24.     player1_common = []
  25.     player2_common = []
  26.  
  27.     for key1, skills1 in some_dict[player_one].items():
  28.         if key1 not in player1_common:
  29.             player1_common.append(key1)
  30.  
  31.     for key2, skills2 in some_dict[player_two].items():
  32.         if key2 not in player2_common:
  33.             player2_common.append(key2)
  34.  
  35.     for el in player1_common:
  36.         if el in player2_common:
  37.             if some_dict[player_one][el] > some_dict[player_two][el]:
  38.                 del some_dict[player_two]
  39.                 del total_skills_points[player_two]
  40.             else:
  41.                 del some_dict[player_one]
  42.                 del total_skills_points[player_one]
  43.     return some_dict
  44.  
  45.  
  46. data = input()
  47. my_dict = {}
  48. total_skills_points = {}
  49. while not data == 'Season end':
  50.     if ' -> ' in data:
  51.         details = data.split(" -> ")
  52.         player = details[0]
  53.         position = details[1]
  54.         skill_points = int(details[2])
  55.         if player not in my_dict.keys():
  56.             my_dict[player] = {position: skill_points}
  57.         else:
  58.             if position not in my_dict[player]:
  59.                 my_dict[player].update({position: skill_points})
  60.             else:
  61.                 old_score = my_dict[player][position]
  62.                 my_dict[player].update({position: max(skill_points, old_score)})
  63.  
  64.  
  65.     elif ' vs ' in data:
  66.         details = data.split(' vs ')
  67.         player1 = details[0]
  68.         player2 = details[1]
  69.         if is_players_valid(my_dict, player1, player2):
  70.             my_dict = time_for_duel(my_dict, player1, player2)
  71.  
  72.     total_skills_points = (calculate_total_skill_points(my_dict))
  73.     data = input()
  74.  
  75. for name, points in sorted(total_skills_points.items(), key=lambda kv: (-kv[1], kv[0])):
  76.     print(f'{name}: {points} skill')
  77.     for name1, points1 in sorted(my_dict[name].items(), key=lambda kv: (-kv[1], kv[0])):
  78.         print(f'- {name1} <::> {points1}')
  79.  
Add Comment
Please, Sign In to add comment