Advertisement
go6odn28

3_moba_chalenger

May 14th, 2024
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. def duel_starts(moba_players_data, player_one, player_two):
  2.     common_positions = []
  3.     positions_one = []
  4.     positions_two = []
  5.     for key_one, value_one in moba_players_data.items():
  6.         if key_one == player_one:
  7.             positions_one = list(x for x in moba_players_data[key_one].keys() if x != "total_skill")
  8.             for key_two, value_two in moba_players_data.items():
  9.                 if key_two == player_two:
  10.                     positions_two = list(x for x in moba_players_data[key_two].keys() if x != "total_skill")
  11.  
  12.     for curr_position in positions_one:
  13.         if curr_position in positions_two:
  14.             common_positions.append(curr_position)
  15.     if len(common_positions) > 0:
  16.         if moba_players_data[player_one]["total_skill"] > moba_players_data[player_two]["total_skill"]:
  17.             moba_players_data.pop(player_two)
  18.         elif moba_players_data[player_one]["total_skill"] < moba_players_data[player_two]["total_skill"]:
  19.             moba_players_data.pop(player_one)
  20.  
  21.     return moba_players_data
  22.  
  23.  
  24. def print_result(sorted_moba_players):
  25.     for player, positions in sorted_moba_players.items():
  26.         print(f"{player}: {positions['total_skill']} skill")
  27.         sorted_positions = dict(sorted(positions.items(), key=lambda x: x[1], reverse=True))
  28.         for key, value in sorted_positions.items():
  29.             if key != "total_skill":
  30.                 print(f"- {key} <::> {value}")
  31.  
  32.  
  33. def take_info(moba_players_data, name, position, skill):
  34.     if name not in moba_players_data:
  35.         moba_players_data[name] = {"total_skill": 0, position: 0}
  36.  
  37.     if position not in moba_players_data[name]:
  38.         moba_players_data[name][position] = 0
  39.     else:
  40.         moba_players_data[name]["total_skill"] -= moba_players_data[name][position]
  41.         if skill < moba_players_data[name][position]:
  42.             skill = moba_players_data[name][position]
  43.     moba_players_data[name][position] = skill
  44.     moba_players_data[name]["total_skill"] += skill
  45.  
  46.     return moba_players_data
  47.  
  48.  
  49. def main():
  50.     moba_players_data = {}
  51.     while True:
  52.         players_info = input().split()
  53.         if len(players_info) == 2:
  54.             break
  55.         if players_info[1] == "->":
  56.             name, position, skill = players_info[0], players_info[2], int(players_info[4])
  57.  
  58.             moba_players_data = take_info(moba_players_data, name, position, skill)
  59.  
  60.         elif players_info[1] == "vs":
  61.             player_one, player_two = players_info[0], players_info[2]
  62.             moba_players_data = duel_starts(moba_players_data, player_one, player_two)
  63.  
  64.     sorted_players = sorted(moba_players_data, key=lambda x: (moba_players_data[x]["total_skill"]), reverse=True)
  65.     sorted_moba_players = {key: moba_players_data[key] for key in sorted_players}
  66.  
  67.     print_result(sorted_moba_players)
  68.  
  69.  
  70. if __name__ == "__main__":
  71.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement