Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import jdk.nashorn.internal.ir.IfNode;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- import java.util.regex.MatchResult;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- public class NetherRealms {
- public static void main(String[] args) throws IOException{
- BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
- String [] names = console.readLine().split(",\\s+");
- Arrays.sort(names);
- Map<Integer, Double> demons = new HashMap<>();
- String namePatternString = "[a-zA-Z]";
- Pattern namePattern = Pattern.compile(namePatternString);
- String damagePatternString = "(\\+|-?\\d+)\\.?(\\d+)?";
- Pattern damagePattern = Pattern.compile(damagePatternString);
- String multiply = "[*]";
- Pattern multiplyPattern = Pattern.compile(multiply);
- String divide = "/";
- Pattern dividePattern = Pattern.compile(divide);
- for (String name:
- names) {
- int na = name.split(",|\\s+").length;
- if (na > 1)
- {
- continue;
- }
- else
- {
- List<String> nameChar = new ArrayList<>();
- List<String> damageNum = new ArrayList<>();
- Matcher nameMatch = namePattern.matcher(name);
- Matcher damageMatche = damagePattern.matcher(name);
- Matcher multiplyMatch = multiplyPattern.matcher(name);
- Matcher divideMatch = dividePattern.matcher(name);
- int multiplySum = 0;
- int divideSum = 0;
- int health = 0;
- double damage = 0.00;
- while (nameMatch.find())
- {
- nameChar.add(nameMatch.group());
- }
- while (damageMatche.find())
- {
- damageNum.add(damageMatche.group());
- }
- while (multiplyMatch.find())
- {
- multiplySum++;
- }
- while (divideMatch.find())
- {
- divideSum++;
- }
- char[] chars = nameChar.stream().collect(Collectors.joining()).toCharArray();
- double[] numbers = new double[damageNum.size()];
- for (int i = 0; i < numbers.length; i++) {
- numbers[i] = Double.parseDouble(damageNum.get(i));
- }
- for (Character x:
- chars) {
- health += x;
- }
- for (Double y:
- numbers) {
- damage += y;
- }
- if (multiplySum > 0)
- {
- damage = (damage * multiplySum * 2);
- }
- else if (divideSum > 0)
- {
- damage = damage / (divideSum * 2);
- }
- System.out.printf("%s - %d health, %.2f damage%n", name, health, damage);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement