Advertisement
GalinaKG

MOBA Challenger

Jul 12th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. data = {}  # {player: {position: skill}}
  2.  
  3. while True:
  4.     command = input()
  5.     if command == 'Season end':
  6.         break
  7.  
  8.     if ' -> ' in command:
  9.         player, position, skill = command.split(' -> ')
  10.  
  11.         if player not in data:
  12.             data[player] = {position: int(skill)}
  13.  
  14.         elif position not in data[player].keys():
  15.             data[player][position] = int(skill)
  16.  
  17.         else:
  18.             data[player][position] = max(data[player][position], int(skill))
  19.  
  20.     elif ' vs ' in command:
  21.         p1, p2 = command.split(' vs ')
  22.  
  23.         if p1 in data.keys() and p2 in data.keys():
  24.             for p1_position in data[p1].keys():
  25.                 if p1_position in data[p2].keys():
  26.                     p1_skill = sum(data[p1].values())
  27.                     p2_skill = sum(data[p2].values())
  28.                     if p1_skill < p2_skill:
  29.                         data.pop(p1)
  30.                     elif p2_skill < p1_skill:
  31.                         data.pop(p2)
  32.                     break
  33.  
  34. player_points = [(p, sum(data[p].values())) for p in data.keys()]
  35. player_ranking = [rank for rank in sorted(player_points, key=lambda item: (-item[1], item[0]))]
  36.  
  37. for rank in player_ranking:
  38.     player, skill = rank
  39.     print(f"{player}: {skill} skill")
  40.     position_ranking = [rank for rank in sorted(data[player].items(), key=lambda item: (-item[1], item[0]))]
  41.     output = [f'- {pos} <::> {skill}' for pos, skill in position_ranking]
  42.     print(*output, sep='\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement