Advertisement
Tsuki11

Untitled

Jun 28th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6.  
  7. public class Task_1 {
  8. public static void main(String[] args) throws IOException {
  9. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11. ArrayDeque<Integer> firstBomb = offerInQueue(reader);
  12.  
  13. ArrayDeque<Integer> secondBomb = new ArrayDeque<>();
  14. pushInTheStack(reader, secondBomb);
  15.  
  16.  
  17. Map<String, Integer> values = new HashMap<>();
  18. values.put("Datura Bombs", 0);
  19. values.put("Cherry Bombs", 0);
  20. values.put("Smoke Decoy Bombs", 0);
  21.  
  22. int datura = 0;
  23. int cherry = 0;
  24. int smokey = 0;
  25. boolean hasAll = false;
  26.  
  27. while (!firstBomb.isEmpty() && !secondBomb.isEmpty()) {
  28. if (datura >= 3 && cherry >= 3 && smokey >= 3) {
  29. hasAll = true;
  30. break;
  31. }
  32.  
  33. int sum = firstBomb.peek() + secondBomb.peek();
  34. int prev;
  35. switch (sum) {
  36. case 40:
  37. datura++;
  38. prev = values.get("Datura Bombs");
  39. prev += 1;
  40. values.put("Datura Bombs", prev);
  41. firstBomb.poll();
  42. secondBomb.pop();
  43. break;
  44. case 60:
  45. cherry++;
  46. prev = values.get("Cherry Bombs");
  47. prev += 1;
  48. values.put("Cherry Bombs", prev);
  49. firstBomb.poll();
  50. secondBomb.pop();
  51. break;
  52. case 120:
  53. smokey++;
  54. prev = values.get("Smoke Decoy Bombs");
  55. prev += 1;
  56. values.put("Smoke Decoy Bombs", prev);
  57. firstBomb.poll();
  58. secondBomb.pop();
  59. break;
  60. default:
  61. int bombLast = secondBomb.pop();
  62. bombLast -= 5;
  63. secondBomb.push(bombLast);
  64. break;
  65. }
  66.  
  67.  
  68. }
  69.  
  70. if(hasAll){
  71. System.out.println("Bene! You have successfully filled the bomb pouch!");
  72. }else{
  73. System.out.println("You don't have enough materials to fill the bomb pouch.");
  74. }
  75.  
  76.  
  77. StringBuilder result = new StringBuilder();
  78. if (firstBomb.size() > 0) {
  79. result.append("Bomb Effects: ");
  80. for (Integer material : firstBomb) {
  81. result.append(material).append(", ");
  82. }
  83. System.out.println(result.toString().substring(0, result.lastIndexOf(",")));
  84. }else{
  85. System.out.println("Bomb Effects: empty");
  86. }
  87.  
  88. result.setLength(0);
  89.  
  90. if (secondBomb.size() > 0) {
  91. result.append("Bomb Casings: ");
  92. for (Integer integer : secondBomb) {
  93. result.append(integer).append(", ");
  94. }
  95. System.out.println(result.toString().substring(0, result.lastIndexOf(",")));
  96. }else{
  97. System.out.println("Bomb Casings: empty");
  98. }
  99.  
  100. values.entrySet().stream()
  101. .filter(c -> c.getValue() >=0)
  102. .sorted(Map.Entry.comparingByKey())
  103. .forEach(e -> System.out.println(e.getKey() + ": " + e.getValue()));
  104.  
  105.  
  106. }
  107.  
  108. private static ArrayDeque<Integer> offerInQueue(BufferedReader reader) throws IOException {
  109. return Arrays.stream(reader.readLine().split(", "))
  110. .mapToInt(Integer::parseInt)
  111. .boxed()
  112. .collect(Collectors.toCollection(ArrayDeque::new));
  113. }
  114.  
  115. private static void pushInTheStack(BufferedReader reader, Deque<Integer> stack) throws IOException {
  116. Arrays.stream(reader.readLine().split(", "))
  117. .mapToInt(Integer::parseInt)
  118. .forEach(stack::push);
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement