Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class lqlq{
- public static void main(String[]args){
- Scanner sc=new Scanner(System.in);
- Map<String, List<Integer>> HEROES = new TreeMap<>();
- int times=Integer.parseInt(sc.nextLine());
- while (times>0){
- String[]input=sc.nextLine().split("\\s+");
- HEROES.putIfAbsent(input[0],new ArrayList<>());
- int HP=Integer.parseInt(input[1]);
- int MP=Integer.parseInt(input[2]);
- if(HP>=0 && HP<=100 && MP>=0 && MP<=200) {
- List<Integer> points = HEROES.get(input[0]);
- points.add(HP, MP);
- }
- times--;
- }
- String take=sc.nextLine();
- while(!take.equals("End")){
- String[]intake=take.split(" - ");
- String cases=intake[0];
- String heroName=intake[1];
- switch (cases){
- case"CastSpell":
- int MPneeded=Integer.parseInt(intake[2]);
- String spellName=intake[3];
- List<Integer> manaPoints = HEROES.get(heroName);
- int currentMP=manaPoints.get(1);
- if(currentMP>=MPneeded){
- manaPoints.set(1,(currentMP-MPneeded));
- HEROES.get(heroName).set(1,(currentMP-MPneeded));
- System.out.printf("%s has successfully cast %s and now has %d MP!",heroName,spellName,(currentMP-MPneeded));
- System.out.println();
- }else{
- System.out.printf("%s does not have enough MP to cast %s!",heroName,spellName);
- System.out.println();
- }
- break;
- case"TakeDamage":
- int damage=Integer.parseInt(intake[1]);
- String attacker=intake[2];
- List<Integer> healthPoints = HEROES.get(heroName);
- int currentHP=healthPoints.get(0);
- if((currentHP-damage)>0){
- HEROES.get(heroName).set(0,(currentHP-damage));
- System.out.printf("%s was hit for %d HP by %s and now has %d HP left!",heroName,damage,attacker,(currentHP-damage));
- System.out.println();
- }else{
- HEROES.remove(heroName);
- System.out.printf("%s has been killed by %s",heroName,attacker);
- System.out.println();
- }
- break;
- case"Recharge":
- List<Integer> recharge = HEROES.get(heroName);
- int amount=Integer.parseInt(intake[2]);
- int currentA=recharge.get(1);
- if((amount+currentA)>200){
- HEROES.get(heroName).set(1,200);
- System.out.printf("%s recharged for %d MP!",heroName,((amount+currentA)-200));
- System.out.println();
- }else {
- HEROES.get(heroName).set(1,(amount+currentA));
- System.out.printf("%s recharged for %d MP!",heroName,((amount)));
- System.out.println();
- }
- break;
- case"Heal":
- List<Integer> rechargeHP = HEROES.get(heroName);
- int amountHP=Integer.parseInt(intake[2]);
- int currentHP1=rechargeHP.get(0);
- if((amountHP+currentHP1)>100){
- HEROES.get(heroName).set(1,100);
- System.out.printf("%s healed for %d HP!",heroName,((amountHP+currentHP1)-100));
- System.out.println();
- }else{
- System.out.printf("%s healed for %d HP!",heroName,(amountHP));
- System.out.println();
- }
- break;
- default:
- throw new IllegalStateException("wrong input!@#!!@!");
- }
- take=sc.nextLine();
- }
- HEROES
- .entrySet()
- .stream()
- .sorted((h1,h2) -> h2.getValue().size()-h1.getValue().size())
- .forEach(h -> {
- System.out.print(String.format("%s", h.getKey()));
- //System.out.printf(String.join("HP: ,%d%n", h.getValue()));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement