viligen

moba_challenger

Nov 10th, 2021 (edited)
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1. def total_points_player(dict_, gamer):
  2.     if gamer in dict_:
  3.         total_points = 0
  4.         for k, v in dict_.items():
  5.             if k == gamer:
  6.                 for sub_k, sub_v in v.items():
  7.                     total_points += sub_v
  8.         return total_points
  9.  
  10.  
  11. game_stats = {}
  12. players_total_pnts = {}
  13. is_duel = False
  14.  
  15. while True:
  16.     data = input()
  17.     if "Season end" in data:
  18.         break
  19.     elif " -> " in data:
  20.         player, position, skill = data.split(" -> ")
  21.         skill = int(skill)
  22.         if player not in game_stats:
  23.             game_stats[player] = {position: skill}
  24.         elif position not in game_stats[player]:
  25.             game_stats[player].update({position: skill})
  26.         else:
  27.             if game_stats[player][position] < skill:
  28.                 game_stats[player][position] = skill
  29.     elif " vs " in data:
  30.         player1_duel, player2_duel = data.split(" vs ")
  31.         is_duel = False
  32.         if player1_duel in game_stats and player2_duel in game_stats:
  33.             for pos1, v1 in game_stats[player1_duel].items():
  34.                 for pos2, v2 in game_stats[player2_duel].items():
  35.                     if pos1 == pos2:
  36.                         is_duel = True
  37.                         break
  38.                 if is_duel:
  39.                     break
  40.             if is_duel:
  41.                 if total_points_player(game_stats, player1_duel) > total_points_player(game_stats, player2_duel):
  42.                     del game_stats[player2_duel]
  43.                 elif total_points_player(game_stats, player1_duel) < total_points_player(game_stats, player2_duel):
  44.                     del game_stats[player1_duel]
  45. for player, stats in game_stats.items():
  46.     total_pnts = total_points_player(game_stats, player)
  47.     players_total_pnts[player] = total_pnts
  48.  
  49. for player_, points_ in sorted(players_total_pnts.items(), key=lambda kvp: (-kvp[1], kvp[0])):
  50.     print(f"{player_}: {points_} skill")
  51.     for pl, stats_ in game_stats.items():
  52.         if player_ == pl:
  53.             for pos, skill in sorted(stats_.items(), key=lambda kvp: (-kvp[1], kvp[0])):
  54.                 print(f"- {pos} <::> {skill}")
  55.                
  56.  
Add Comment
Please, Sign In to add comment