Advertisement
Guest User

MOBA Challenger

a guest
Jul 15th, 2020
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. line = input()
  2. player_position_skill = {}
  3. total_points = {}
  4.  
  5.  
  6. while line != 'Season end':
  7.     tokens = line.split()
  8.     if tokens[1] == '->':
  9.         tokens = ''.join(tokens)
  10.         tokens = tokens.split('->')
  11.         player = tokens[0]
  12.         position = tokens[1]
  13.         skill = int(tokens[2])
  14.         if player not in player_position_skill:
  15.             player_position_skill[player] = {}
  16.             player_position_skill[player][position] = skill
  17.             total_points[player] = skill
  18.         else:
  19.             if position not in player_position_skill[player]:
  20.                 player_position_skill[player][position] = skill
  21.                 total_points[player] += skill
  22.             else:
  23.                 if player_position_skill[player][position] < skill:
  24.                     player_position_skill[player][position] = 0
  25.                     player_position_skill[player][position] += skill
  26.                     total_points[player] -= total_points[player]
  27.                     total_points[player] += skill
  28.  
  29.     elif tokens[1] == 'vs':
  30.         tokens = ''.join(tokens)
  31.         tokens = tokens.split('vs')
  32.         player_1 = tokens[0]
  33.         player_2 = tokens[1]
  34.         player_1_dict = {}
  35.         player_2_dict = {}
  36.         if player_1 in player_position_skill and player_2 in player_position_skill:
  37.             for key, value in player_position_skill.items():
  38.                 if key == player_1:
  39.                     for position, points in value.items():
  40.                         player_1_dict[position] = points
  41.  
  42.                 elif key == player_2:
  43.                     for position, points in value.items():
  44.                         player_2_dict[position] = points
  45.  
  46.             for p, s in player_1_dict.items():
  47.                 if p in player_2_dict:
  48.                     if player_1_dict[p] > player_2_dict[p]:
  49.                         del player_position_skill[player_2]
  50.                         del total_points[player_2]
  51.                     elif player_2_dict[p] > player_1_dict[p]:
  52.                         del player_position_skill[player_1]
  53.                         del total_points[player_1]
  54.  
  55.  
  56.     line = input()
  57.  
  58.  
  59. total_points = dict(sorted(total_points.items(), key=lambda x: (-x[1], x[0])))
  60. for player, points in total_points.items():
  61.     print(f'{player}: {points} skill')
  62.     for key, value in player_position_skill.items():
  63.         value = dict(sorted(value.items(), key=lambda x: (-x[1], x[0])))
  64.         if player == key:
  65.             for position, skill in value.items():
  66.                 print(f'- {position} <::> {skill}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement