Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Sirakov4444 avatar Sirakov4444 11 Точки

100/100 :

 

import java.nio.charset.IllegalCharsetNameException;
import java.util.*;

public class practice{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);

        Map<String,Integer> HEROEShp = new TreeMap<>();
        Map<String,Integer> HEROESwp = new TreeMap<>();

        int times=Integer.parseInt(sc.nextLine());
        for(int i=0;i<times;i++){
            String[]input=sc.nextLine().split("\\s+");
            String name=input[0];
            int HP=Integer.parseInt(input[1]);
            int MP=Integer.parseInt(input[2]);

            if(!HEROEShp.containsKey(name) && !HEROESwp.containsKey(name)) {
                 HEROEShp.put(name,HP);
                 HEROESwp.put(name,MP);
            }
        }
        String input2=sc.nextLine();
        while(!input2.equals("End")){
            String[]commands=input2.split(" - ");
            String cases=commands[0];
            String heroName=commands[1];
            switch (cases){
                case"CastSpell":
                    int neededMP=Integer.parseInt(commands[2]);
                    String spellName=commands[3];
                    int currentMP=HEROESwp.get(heroName);
                    if(currentMP>=neededMP){
                        currentMP -=neededMP;
                        HEROESwp.put(heroName,currentMP);
                        System.out.printf
                                ("%s has successfully cast %s and now has %d MP!",heroName,spellName,(currentMP));
                        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(commands[2]);
                    String attacker=commands[3];
                    int currentHP=HEROEShp.get(heroName);
                    currentHP-=damage;
                    HEROEShp.put(heroName,currentHP);
                    if((currentHP)>0){
                        System.out.printf("%s was hit for %d HP by %s and now has %d HP left!",
                                heroName,damage,attacker,(currentHP));
                        System.out.println();
                    }else{
                        HEROEShp.remove(heroName);
                        HEROESwp.remove(heroName);
                        System.out.printf("%s has been killed by %s!",heroName,attacker);
                        System.out.println();
                    }
                    break;
                case"Recharge":
                    int amount=Integer.parseInt(commands[2]);
                    int currentMP2=HEROESwp.get(heroName);
                    if(currentMP2+amount>200){
                        HEROESwp.put(heroName,200);
                        System.out.printf("%s recharged for %d MP!",heroName,(200-currentMP2));
                        System.out.println();
                    }else{
                        HEROESwp.put(heroName,(amount+(HEROESwp.get(heroName))));
                        System.out.printf("%s recharged for %d MP!",heroName,(amount));
                        System.out.println();
                    }
                    break;
                case"Heal":
                    int amountHP= Integer.parseInt(commands[2]);
                    int currentHP2=HEROEShp.get(heroName);

                    if((currentHP2+amountHP)>100){
                        HEROEShp.put(heroName,100);
                        System.out.printf("%s healed for %d HP!"
                                ,heroName,(100-(currentHP2)));
                        System.out.println();
                    }else{
                        HEROEShp.put(heroName,(currentHP2+amountHP));
                        System.out.printf("%s healed for %d HP!"
                                ,heroName,(amountHP));
                        System.out.println();
                    }
                    break;
                    default:
                        throw new IllegalStateException("KUR KUR");
            }
            input2=sc.nextLine();

        }

        HEROEShp
                .entrySet()
                .stream()
                .sorted((n1, n2) -> n2.getValue().compareTo(n1.getValue()))
                .forEach(n->{
                    String name=n.getKey();
                    int name4=n.getValue();
                    int name5=HEROESwp.get((name));
                    System.out.print(name);
                    System.out.println();
                    System.out.printf("  HP: %d%n",name4);
                    System.out.printf("  MP: %d%n",name5);
                });

    }

}
0
09/04/2020 20:30:30
milipt avatar milipt 10 Точки

https://pastebin.com/jWVJFrBT

Аз пробвах с обекти, поизмъчих се , но стана.

2
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.