Advertisement
SIRAKOV4444

Untitled

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