SimeonTs

SUPyF2 Dict-More-Ex. - 03. MOBA Challenger

Oct 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.87 KB | None | 0 0
  1. """
  2. Dictionaries - More Exercises
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1738#2
  4.  
  5. SUPyF2 Dict-More-Ex. - 03. MOBA Challenger
  6.  
  7. Problem:
  8. Pesho is a pro MOBA player, he is struggling to become а master of the Challenger tier.
  9. So he watches carefully the statistics in the tier.
  10. You will receive several input lines in one of the following formats:
  11. "{player} -> {position} -> {skill}"
  12. "{player} vs {player}"
  13. The player and position are strings, the given skill will be an integer number. You need to keep track of every player.
  14. When you receive a player and his position and skill, add him to the player pool, if he isn`t present,
  15. else add his position and skill or update his skill, only if the current position skill is lower than the new value.
  16. If you receive "{player} vs {player}" and both players exist in the tier, they duel with the following rules:
  17. Compare their positions, if they got at least one in common,
  18. the player with better total skill points wins and the other is demoted from the tier -> remove him.
  19. If they have same total skill points, the duel is tie and they both continue in the Season.
  20. If they don`t have positions in common, the duel isn`t happening and both continue in the Season.
  21. You should end your program when you receive the command "Season end". At that point you should print the players,
  22. ordered by total skill in desecending order,
  23. then ordered by player name in ascending order.
  24. Foreach player print their position and skill, ordered desecending by skill,
  25. then ordered by position name in ascending order.
  26. Input / Constraints
  27. • The input comes in the form of commands in one of the formats specified above.
  28. • Player and position will always be one word string, containing no whitespaces.
  29. • Skill will be an integer in the range [0, 1000].
  30. • There will be no invalid input lines.
  31. • The programm ends when you receive the command "Season end".
  32. Output
  33. • The output format for each player is:
  34. "{player}: {totalSkill} skill"
  35. "- {position} <::> {skill}"
  36. Examples:
  37. Input:
  38. Pesho -> Adc -> 400
  39. Gosho -> Jungle -> 300
  40. Stamat -> Mid -> 200
  41. Stamat -> Support -> 250
  42. Season end
  43.  
  44. Output:
  45. Stamat: 450 skill
  46. - Support <::> 250
  47. - Mid <::> 200
  48. Pesho: 400 skill
  49. - Adc <::> 400
  50. Gosho: 300 skill
  51. - Jungle <::> 300
  52.  
  53. Comments:
  54. We order the players by total skill points descending, then by name.
  55. We print every position along its skill ordered descending by skill, then by position name.
  56.  
  57. Input:
  58. Pesho -> Adc -> 400
  59. Bush -> Tank -> 150
  60. Faker -> Mid -> 200
  61. Faker -> Support -> 250
  62. Faker -> Tank -> 250
  63. Pesho vs Faker
  64. Faker vs Bush
  65. Faker vs Hide
  66. Season end
  67.  
  68. Output:
  69. Faker: 700 skill
  70. - Support <::> 250
  71. - Tank <::> 250
  72. - Mid <::> 200
  73. Pesho: 400 skill
  74. - Adc <::> 400
  75.  
  76. Comments:
  77. Faker and Pesho don`t have common position, so the duel isn`t valid.
  78. Faker wins vs Bush /common position: "Tank". Bush is demoted.
  79. Hide doesn`t exist so the duel isn`t valid.
  80. We print every player left in the tier.
  81.  
  82. #TODO Judge 80/100 (last two tests are with invalid input)
  83. """
  84. players_pool = {}
  85.  
  86. while True:
  87.     command = input()
  88.     if command == "Season end":
  89.         break
  90.  
  91.     # Filling in players
  92.     if "->" in command:
  93.         player = command.split(" -> ")[0]
  94.         position = command.split(" -> ")[1]
  95.         skill = int(command.split(" -> ")[2])
  96.  
  97.         if player not in players_pool:
  98.             players_pool[player] = {position: skill}
  99.         elif player in players_pool:
  100.             if position not in players_pool[player]:
  101.                 players_pool[player][position] = skill
  102.             elif position in players_pool[player]:
  103.                 if skill > players_pool[player][position]:
  104.                     players_pool[player][position] = skill
  105.  
  106.     # Time for battle:
  107.     elif "vs" in command:
  108.         player_one = command.split(" vs ")[0]
  109.         player_two = command.split(" vs ")[1]
  110.  
  111.         if player_one in players_pool and player_two in players_pool:
  112.             for position_player_one, skill_player_one in players_pool[player_one].items():
  113.                 for position_player_two, skill_player_two in players_pool[player_two].items():
  114.                     if position_player_one == position_player_two:
  115.                         if skill_player_one == skill_player_two:
  116.                             continue
  117.                         elif skill_player_one > skill_player_two:
  118.                             players_pool.pop(player_two)
  119.                         elif skill_player_two > skill_player_one:
  120.                             players_pool.pop(player_one)
  121.  
  122. # print the players ordered and the total skill
  123. for player, all_skills in sorted(players_pool.items(), key=lambda x: (-sum(x[1].values()), x[0])):
  124.     print(f"{player}: {sum(all_skills.values())} skill")
  125.     for skill_name, skill_points in sorted(all_skills.items(), key=lambda x: (-x[1], x[0])):
  126.         print(f"- {skill_name} <::> {skill_points}")
Add Comment
Please, Sign In to add comment