Advertisement
Guest User

Untitled

a guest
Jul 24th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1.  
  2. import java.lang.reflect.Array;
  3. import java.util.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Exercise_Zad_5_NR {
  8. public static void main(String[] args) {
  9. Scanner scan = new Scanner (System.in);
  10.  
  11. String input = scan.nextLine();
  12.  
  13. String[] myDeamons = input.split(",\\s+");
  14. Map<String, List<Double>> myMap = new TreeMap<>();
  15.  
  16.  
  17. for (int i = 0; i < myDeamons.length; i++) {
  18.  
  19. String currDeamon = myDeamons[i].replaceAll("\\s+", ""); // Tova go vidqh vav Foruma !!!
  20.  
  21. String regexHealth = "[^0-9+\\-*\\/\\.]"; // "[^\\d.+/*,-]*"; // [^\\d+\\-*\\/.]+ ???
  22. Pattern myPat = Pattern.compile(regexHealth);
  23. Matcher myMatch = myPat.matcher(currDeamon);
  24. String currHealtString = ""; // [^0-9+\-*\/\.]
  25.  
  26. double currHealtToPut = 0;
  27.  
  28. while (myMatch.find()){
  29. currHealtString += myMatch.group();
  30. }
  31.  
  32. for (int k = 0; k < currHealtString.length(); k++) {
  33. currHealtToPut += currHealtString.charAt(k);
  34. }
  35. // [-+]?\\d\\.?\\d* ???
  36. String regexDamage = "([-+]?[0-9]*\\.[0-9]+|[0-9]+)|([-+]?[0-9]+)"; // "([+-]?[\\d]+[.]?[\\d]*)";
  37. Pattern myPattern2 = Pattern.compile(regexDamage);
  38. Matcher myMatcher2 = myPattern2.matcher(currDeamon); // [-+]?[0-9]*\.[0-9]+|[0-9]+)|([-+]?[0-9]+
  39.  
  40.  
  41. double currDamage = 0;
  42.  
  43. while (myMatcher2.find()){
  44.  
  45. currDamage += Double.parseDouble(myMatcher2.group());
  46. }
  47.  
  48. for (int j = 0; j < currDeamon.length(); j++) {
  49.  
  50. char temp = currDeamon.charAt(j);
  51.  
  52. if (temp == '/')
  53. currDamage /= 2;
  54. else if (temp == '*')
  55. currDamage *= 2;
  56. }
  57.  
  58. myMap.putIfAbsent(currDeamon, new ArrayList<>(Arrays.asList(0.0 , 0.0)));
  59.  
  60. double oldHealt = myMap.get(currDeamon).get(0);
  61. myMap.get(currDeamon).set(0, oldHealt + currHealtToPut);
  62.  
  63. double oldDamage = myMap.get(currDeamon).get(1);
  64. myMap.get(currDeamon).set(1, oldDamage + currDamage);
  65.  
  66. }
  67.  
  68. for (Map.Entry<String, List<Double>> entry : myMap.entrySet()) {
  69. System.out.printf("%s - %.0f health, %.2f damage%n",entry.getKey(), entry.getValue().get(0), entry.getValue().get(1) );
  70. }
  71. }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement