SimeonTs

SUPyF Exam Preparation 2 - 03. Arena Tier

Aug 16th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.67 KB | None | 0 0
  1. """
  2. Basics OOP Principles
  3. Check your solution: https://judge.softuni.bg/Contests/Practice/Index/1578#2
  4.  
  5. SUPyF Exam Preparation 2 - 03. Arena Tier
  6. Problem:
  7. Pesho is a pro gladiator, he is struggling to become master of the Arena. // TODO some more story
  8. You will receive several input lines in one of the following formats:
  9. "{gladiator} -> {technique} -> {skill}"
  10. "{gladiator} vs {gladiator}"
  11. The gladiator and technique are strings, the given skill will be an integer number.
  12. You need to keep track of every gladiator.
  13. When you receive a gladiator and his technique and skill, add him to the gladiator pool, if he isn`t present,
  14. else add his technique or update his skill, only if the current technique skill is lower than the new value.
  15. If you receive "{gladiator} vs {gladiator}" and both gladiators exist in the tier, they duel with the following rules:
  16. Compare their techniques, if they got at least one in common,
  17. the gladiator with better total skill points wins and the other is demoted from the tier -> remove him.
  18. If they don`t have techniques in common, the duel isn`t happening and both continue in the Season.
  19. You should end your program when you receive the command "Ave Cesar". At that point you should print the gladiators,
  20. ordered by total skill in desecending order, then ordered by name in ascending order.
  21. Foreach gladiator print their technique and skill, ordered desecending,
  22. then ordered by technique name in ascending order
  23. Input / Constraints
  24. You will receive input on several lines.
  25. • The input comes in the form of commands in one of the formats specified above.
  26. • Gladiator and technique will always be one word string, containing no whitespaces.
  27. • Skill will be an integer in the range [0, 1000].
  28. • There will be no invalid input lines.
  29. • The programm ends when you receive the command "Ave Cesar".
  30.  
  31. Output
  32. • The output format for each gladiator is:
  33. "{gladiator}: {totalSkill} skill"
  34. "- {technique} <!> {skill}"
  35.  
  36. Scroll down to see examples.
  37.  
  38. Input:
  39. Pesho -> BattleCry -> 400
  40. Gosho -> PowerPunch -> 300
  41. Stamat -> Duck -> 200
  42. Stamat -> Tiger -> 250
  43. Ave Cesar
  44.  
  45. Output:
  46. Stamat: 450 skill
  47. - Tiger <!> 250
  48. - Duck <!> 200
  49. Pesho: 400 skill
  50. - BattleCry <!> 400
  51. Gosho: 300 skill
  52. - PowerPunch <!> 300
  53.  
  54. Input:
  55. Pesho -> Duck -> 400
  56. Julius -> Shield -> 150
  57. Gladius -> Heal -> 200
  58. Gladius -> Support -> 250
  59. Gladius -> Shield -> 250
  60. Pesho vs Gladius
  61. Gladius vs Julius
  62. Gladius vs Gosho
  63. Ave Cesar
  64.  
  65. Output:
  66. Gladius: 700 skill
  67. - Support <!> 250
  68. - Shield <!> 250
  69. - Heal <!> 200
  70. Pesho: 400 skill
  71. - Duck <!> 400
  72. """
  73.  
  74.  
  75. class Gladiator:
  76.     def __init__(self, name: str, skills: [], total_skill_points: int):
  77.         self.name = name
  78.         self.skills = skills
  79.         self.total_skill_points = total_skill_points
  80.  
  81.  
  82. class Skill:
  83.     def __init__(self, name: str, value: int):
  84.         self.name = name
  85.         self.value = value
  86.  
  87.  
  88. gladiators_pool = []
  89.  
  90. while True:
  91.     command = input()
  92.     if command == "Ave Cesar":
  93.         break
  94.     if "->" in command:
  95.         gladiator_name, skill_name, skill_value = command.split(" -> ")
  96.         skill_value = int(skill_value)
  97.  
  98.         not_in_pool = True
  99.         for gladiator in gladiators_pool:
  100.             if gladiator.name == gladiator_name:
  101.  
  102.                 skill_not_in_skills = True
  103.  
  104.                 for skill in gladiator.skills:
  105.                     if skill.name == skill_name:
  106.                         skill_not_in_skills = False
  107.  
  108.                         if skill.value < skill_value:
  109.  
  110.                             old_skill_points = skill.value
  111.                             gladiator.total_skill_points -= old_skill_points
  112.                             gladiator.total_skill_points += skill_value
  113.  
  114.                             skill.value = skill_value
  115.  
  116.                 if skill_not_in_skills:
  117.                     gladiator.skills += [Skill(name=skill_name, value=skill_value)]
  118.                     gladiator.total_skill_points += skill_value
  119.  
  120.                 not_in_pool = False
  121.  
  122.         if not_in_pool:
  123.             skill = Skill(name=skill_name, value=skill_value)
  124.             gladiator = Gladiator(name=gladiator_name, skills=[skill], total_skill_points=skill_value)
  125.             gladiators_pool += [gladiator]
  126.  
  127.     elif "vs" in command:
  128.         gladiator_1, vs, gladiator_2 = command.split()
  129.         for gladiator1 in gladiators_pool:
  130.             if gladiator1.name == gladiator_1:
  131.                 for gladiator2 in gladiators_pool:
  132.                     if gladiator2.name == gladiator_2:
  133.  
  134.                         for skill_gl_1 in gladiator1.skills:
  135.                             for skill_gl_2 in gladiator2.skills:
  136.                                 if skill_gl_1.name == skill_gl_2.name:
  137.                                     if gladiator1.total_skill_points > gladiator2.total_skill_points:
  138.                                         if gladiator2 in gladiators_pool:
  139.                                             gladiators_pool.remove(gladiator2)
  140.                                             break
  141.                                     elif gladiator2.total_skill_points > gladiator1.total_skill_points:
  142.                                         if gladiator1 in gladiators_pool:
  143.                                             gladiators_pool.remove(gladiator1)
  144.                                             break
  145.  
  146. gladiators_pool = sorted(sorted(gladiators_pool, key=lambda x: x.name), key=lambda x: x.total_skill_points, reverse=True)
  147.  
  148. for gladiator in gladiators_pool:
  149.     print(f"{gladiator.name}: {gladiator.total_skill_points} skill")
  150.     for skill in sorted(sorted(gladiator.skills, key=lambda x: x.name), key=lambda x: x.value, reverse=True):
  151.         print(f"- {skill.name} <!> {skill.value}")
Add Comment
Please, Sign In to add comment