Advertisement
NinoB

Nether Realms

Mar 7th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1. import jdk.nashorn.internal.ir.IfNode;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.*;
  7. import java.util.regex.MatchResult;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10. import java.util.stream.Collectors;
  11.  
  12. public class NetherRealms {
  13.     public static void main(String[] args) throws IOException{
  14.  
  15.         BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
  16.  
  17.         String [] names = console.readLine().split(",\\s+");
  18.         Arrays.sort(names);
  19.         Map<Integer, Double> demons = new HashMap<>();
  20.  
  21.         String namePatternString = "[a-zA-Z]";
  22.         Pattern namePattern = Pattern.compile(namePatternString);
  23.  
  24.         String damagePatternString = "(\\+|-?\\d+)\\.?(\\d+)?";
  25.         Pattern damagePattern = Pattern.compile(damagePatternString);
  26.  
  27.         String multiply = "[*]";
  28.         Pattern multiplyPattern = Pattern.compile(multiply);
  29.  
  30.         String divide = "/";
  31.         Pattern dividePattern = Pattern.compile(divide);
  32.  
  33.         for (String name:
  34.              names) {
  35.  
  36.             int na = name.split(",|\\s+").length;
  37.             if (na > 1)
  38.             {
  39.                 continue;
  40.             }
  41.             else
  42.             {
  43.                 List<String> nameChar = new ArrayList<>();
  44.                 List<String> damageNum = new ArrayList<>();
  45.  
  46.                 Matcher nameMatch = namePattern.matcher(name);
  47.                 Matcher damageMatche = damagePattern.matcher(name);
  48.                 Matcher multiplyMatch = multiplyPattern.matcher(name);
  49.                 Matcher divideMatch = dividePattern.matcher(name);
  50.  
  51.                 int multiplySum = 0;
  52.                 int divideSum = 0;
  53.                 int health = 0;
  54.                 double damage = 0.00;
  55.  
  56.                 while (nameMatch.find())
  57.                 {
  58.                     nameChar.add(nameMatch.group());
  59.  
  60.                 }
  61.                 while (damageMatche.find())
  62.                 {
  63.                     damageNum.add(damageMatche.group());
  64.                 }
  65.                 while (multiplyMatch.find())
  66.                 {
  67.                     multiplySum++;
  68.                 }
  69.                 while (divideMatch.find())
  70.                 {
  71.                     divideSum++;
  72.                 }
  73.  
  74.                 char[] chars = nameChar.stream().collect(Collectors.joining()).toCharArray();
  75.                 double[] numbers = new double[damageNum.size()];
  76.                 for (int i = 0; i < numbers.length; i++) {
  77.                     numbers[i] = Double.parseDouble(damageNum.get(i));
  78.                 }
  79.  
  80.                 for (Character x:
  81.                         chars) {
  82.                     health += x;
  83.                 }
  84.  
  85.                 for (Double y:
  86.                         numbers) {
  87.                     damage += y;
  88.                 }
  89.  
  90.                 if (multiplySum > 0)
  91.                 {
  92.                     damage = (damage * multiplySum * 2);
  93.                 }
  94.                 else if (divideSum > 0)
  95.                 {
  96.                     damage = damage / (divideSum * 2);
  97.                 }
  98.  
  99.                 System.out.printf("%s - %d health, %.2f damage%n", name, health, damage);
  100.  
  101.             }
  102.  
  103.         }
  104.  
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement