Problem 3. Heroes of Code and Logic VII
https://pastebin.com/WHb2XVAU
-
Programming Fundamentals Final Exam 04.04.2020 Problem 3. Heroes of Code and Logic VII You got your hands on the most recent update on the best MMORPG of all time – Heroes of Code and Logic. You want to play it all day long! So cancel all other arrangements and create your party! On the first line of the standard input you will receive an integer n – the number of heroes that you can choose for your party. On the next n lines, the heroes themselves will follow with their hit points and mana points separated by empty space in the following format: {hero name} {HP} {MP} - where HP stands for hit points and MP for mana points - a hero can have a maximum of 100 HP and 200 MP After you have successfully picked your heroes, you can start playing the game. You will be receiving different commands, each on a new line, separated by " – ", until the "End" command is given. There are several actions that can be performed by the heroes: CastSpell – {hero name} – {MP needed} – {spell name} • If the hero has the required MP, he casts the spell, thus reducing his MP. Print this message: o "{hero name} has successfully cast {spell name} and now has {mana points left} MP!" • If the hero is unable to cast the spell print: o "{hero name} does not have enough MP to cast {spell name}!" TakeDamage – {hero name} – {damage} – {attacker} • Reduce the hero HP by the given damage amount. If the hero is still alive (his HP is greater than 0) print: o "{hero name} was hit for {damage} HP by {attacker} and now has {current HP} HP left!" • If the hero has died, remove him from your party and print: o "{hero name} has been killed by {attacker}!" Recharge – {hero name} – {amount} • The hero increases his MP. If a command is given that would bring the MP of the hero above 200, MP is increased so that it reaches the maximum. Print the following message: o "{hero name} recharged for {amount recovered} MP!" Heal – {hero name} – {amount} • The hero increases his HP. If a command is given that would bring the HP of the hero above 100, HP is increased so that it reaches the maximum. Print the following message: o "{hero name} healed for {amount recovered} HP!" Input • On the first line of the standard input you will receive an integer n • On the next n lines, the heroes themselves will follow with their hit points and mana points separated by empty space in the following format • You will be receiving different commands, each on a new line, separated by " – ", until the "End" command is given Output • Print all members of your party who are still alive, sorted by their HP in descending order, then by their name in ascending order, in the following format (their HP/MP need to be indented 2 spaces): "{hero name} HP: {current HP} MP: {current MP} ..." Constraints • The starting HP/MP of the heroes will be valid, 32-bit integers, will never be negative or exceed the respective limits. • The HP/MP amounts in the commands will never be negative. • The hero names in the commands will always be valid members of your party. No need to check that explicitly Examples Input Output 2 Solmyr 85 120 Kyrre 99 50 Heal - Solmyr - 10 Recharge - Solmyr - 50 TakeDamage - Kyrre - 66 - Orc CastSpell - Kyrre - 15 - ViewEarth End Solmyr healed for 10 HP! Solmyr recharged for 50 MP! Kyrre was hit for 66 HP by Orc and now has 33 HP left! Kyrre has successfully cast ViewEarth and now has 35 MP! Solmyr HP: 95 MP: 170 Kyrre HP: 33 MP: 35 Comments These are examples of successful actions. The different colors denote the commands and their respective messages. Input Output 4 Adela 90 150 SirMullich 70 40 Ivor 1 111 Tyris 94 61 Heal - SirMullich - 50 Recharge - Adela - 100 CastSpell - Tyris - 1000 - Fireball TakeDamage - Tyris - 99 - Fireball TakeDamage - Ivor - 3 - Mosquito End SirMullich healed for 30 HP! Adela recharged for 50 MP! Tyris does not have enough MP to cast Fireball! Tyris has been killed by Fireball! Ivor has been killed by Mosquito! SirMullich HP: 100 MP: 40 Adela HP: 90 MP: 200 Comments Heal – SirMullich healed for 30 HP due to the HP max limit. Recharge – Adela recharged for 50 MP due to the MP max limit. CastSpell – Tyris does not have enough MP to cast the spell. TakeDamage – Tyris`s HP is reduced by 99, thus becoming -5, which means that he is dead. TakeDamage – Ivor`s HP is now -2, so he is dead too. After the "End" command we print the remaining living heroes, sorted by their HP in reverse order.
Когато тествам решението Heal - Solmyr - 10 то зарежда с 15, вместо 10. Не можах да намеря грешката.
-
https://pastebin.com/CEi9hZeU вашият код с малко промени 100/100
https://pastebin.com/LRJ0u3f8 и моят вариант за сравнение