Advertisement
SIRAKOV4444

Untitled

Apr 9th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class lqlq{
  4. public static void main(String[]args){
  5. Scanner sc=new Scanner(System.in);
  6.  
  7. Map<String, List<Integer>> HEROES = new TreeMap<>();
  8.  
  9. int times=Integer.parseInt(sc.nextLine());
  10. while (times>0){
  11. String[]input=sc.nextLine().split("\\s+");
  12. String name=input[0];
  13. HEROES.putIfAbsent(name,new ArrayList<>(1));
  14.  
  15. int HP=Integer.parseInt(input[1]);
  16. int MP=Integer.parseInt(input[2]);
  17. if(HP>=0 && HP<=100 && MP>=0 && MP<=200) {
  18. HEROES.get(name).set(0,HP);
  19. HEROES.get(name).set(1,MP);
  20.  
  21. }
  22. times--;
  23. }
  24. String take=sc.nextLine();
  25. while(!take.equals("End")){
  26. String[]intake=take.split(" - ");
  27. String cases=intake[0];
  28. String heroName=intake[1];
  29. switch (cases){
  30. case"CastSpell":
  31. int MPneeded=Integer.parseInt(intake[2]);
  32. String spellName=intake[3];
  33. List<Integer> manaPoints = HEROES.get(heroName);
  34. int currentMP=manaPoints.get(1);
  35. if(currentMP>=MPneeded){
  36. manaPoints.set(1,(currentMP-MPneeded));
  37. HEROES.get(heroName).set(1,(currentMP-MPneeded));
  38. System.out.printf("%s has successfully cast %s and now has %d MP!",heroName,spellName,(currentMP-MPneeded));
  39. System.out.println();
  40. }else{
  41. System.out.printf("%s does not have enough MP to cast %s!",heroName,spellName);
  42. System.out.println();
  43. }
  44. break;
  45. case"TakeDamage":
  46. int damage=Integer.parseInt(intake[1]);
  47. String attacker=intake[2];
  48. List<Integer> healthPoints = HEROES.get(heroName);
  49. int currentHP=healthPoints.get(0);
  50. if((currentHP-damage)>0){
  51. HEROES.get(heroName).set(0,(currentHP-damage));
  52. System.out.printf("%s was hit for %d HP by %s and now has %d HP left!",heroName,damage,attacker,(currentHP-damage));
  53. System.out.println();
  54. }else{
  55. HEROES.remove(heroName);
  56. System.out.printf("%s has been killed by %s",heroName,attacker);
  57. System.out.println();
  58. }
  59. break;
  60. case"Recharge":
  61. List<Integer> recharge = HEROES.get(heroName);
  62. int amount=Integer.parseInt(intake[2]);
  63. int currentA=recharge.get(1);
  64. if((amount+currentA)>200){
  65. HEROES.get(heroName).set(1,200);
  66. System.out.printf("%s recharged for %d MP!",heroName,((amount+currentA)-200));
  67. System.out.println();
  68. }else {
  69. HEROES.get(heroName).set(1,(amount+currentA));
  70. System.out.printf("%s recharged for %d MP!",heroName,((amount)));
  71. System.out.println();
  72. }
  73. break;
  74. case"Heal":
  75. List<Integer> rechargeHP = HEROES.get(heroName);
  76. int amountHP=Integer.parseInt(intake[2]);
  77. int currentHP1=rechargeHP.get(0);
  78. if((amountHP+currentHP1)>100){
  79. HEROES.get(heroName).set(1,100);
  80. System.out.printf("%s healed for %d HP!",heroName,((amountHP+currentHP1)-100));
  81. System.out.println();
  82. }else{
  83. System.out.printf("%s healed for %d HP!",heroName,(amountHP));
  84. System.out.println();
  85. }
  86. break;
  87. default:
  88. throw new IllegalStateException("wrong input!@#!!@!");
  89. }
  90. take=sc.nextLine();
  91. }
  92. HEROES
  93. .entrySet()
  94. .stream()
  95. .sorted((h1,h2) -> h2.getValue().size()-h1.getValue().size())
  96. .forEach(h -> {
  97. System.out.print(String.format("%s", h.getKey()));
  98. System.out.printf(String.join(" HP: ,%d%n",h.getValue().get(0).toString()));
  99. System.out.printf(String.join(" WP: ,%d%n",h.getValue().get(1).toString()));
  100. });
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement