Advertisement
AngelKejov

Untitled

Oct 17th, 2021
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.75 KB | None | 0 0
  1. package JavaAdvancedExam28June2020;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6.  
  7. public class P01Bombs {
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner sc = new Scanner(System.in);
  11.  
  12.         int[] arr1 = Arrays.stream(sc.nextLine().split(", "))
  13.                 .mapToInt(Integer::parseInt)
  14.                 .toArray();
  15.         ArrayDeque<Integer> queue = new ArrayDeque<>();
  16.         for (int i = 0; i < arr1.length; i++) {
  17.             queue.offer(arr1[i]);
  18.         }
  19.  
  20.         int[] arr2 = Arrays.stream(sc.nextLine().split(", "))
  21.                 .mapToInt(Integer::parseInt)
  22.                 .toArray();
  23.         ArrayDeque<Integer> stack = new ArrayDeque<>();
  24.         for (int i = 0; i < arr2.length; i++) {
  25.             stack.push(arr2[i]);
  26.         }
  27.  
  28.         int daturaBomb = 40;
  29.         int cherryBomb = 60;
  30.         int smokeDecoyBomb = 120;
  31.  
  32.         int daturaCount = 0;
  33.         int cherryCount = 0;
  34.         int smoDecoyCount = 0;
  35.  
  36.         int firstEl = 0;
  37.         int lastEl = 0;
  38.         int sum = 0;
  39.         while (true) {
  40.  
  41.             if (stack.isEmpty() || queue.isEmpty()) {
  42.                 break;
  43.             }
  44.             firstEl = queue.peek();
  45.             lastEl = stack.peek();
  46.             sum = firstEl + lastEl;
  47.  
  48.             if (sum == daturaBomb) {
  49.                 queue.poll();
  50.                 stack.pop();
  51.                 daturaCount++;
  52.             } else if (sum == cherryBomb) {
  53.                 queue.poll();
  54.                 stack.pop();
  55.                 cherryCount++;
  56.             } else if (sum == smokeDecoyBomb) {
  57.                 queue.pop();
  58.                 stack.pop();
  59.                 smoDecoyCount++;
  60.             } else {
  61.                 lastEl -= 5;
  62.                 stack.pop();
  63.                 stack.push(lastEl);
  64.                 sum = 0;
  65.             }
  66.         }
  67.         if (smoDecoyCount == 3 && cherryCount == 3 && daturaCount == 3) {
  68.             System.out.println("Bene! You have successfully filled the bomb pouch!");
  69.         } else {
  70.             System.out.println("You don't have enough materials to fill the bomb pouch.");
  71.         }
  72.  
  73.         if (queue.isEmpty()) {
  74.             System.out.println("Bomb Effects: empty");
  75.         } else {
  76.             System.out.print("Bomb Effects: ");
  77.             queue.forEach(System.out::print);
  78.         }
  79.  
  80.         if (stack.isEmpty()) {
  81.             System.out.println("Bomb Casings: empty");
  82.         } else {
  83.             System.out.print("Bomb Casings: ");
  84.             for (Integer integer : stack) {
  85.                 System.out.print(integer + " ");
  86.             }
  87.         }
  88.  
  89.         System.out.println(cherryCount);
  90.         System.out.println(daturaCount);
  91.         System.out.println(smoDecoyCount);
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement