A_Marinov

Untitled

Feb 19th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.95 KB | None | 0 0
  1. package C00.RetakeExaAugust.June;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6.  
  7. public class P01_Bombs {
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.  
  11.         ArrayDeque<Integer> bombEffect = fillBombQueue(scan);
  12.         ArrayDeque<Integer> bombCasing = fillBombStack(scan);
  13.  
  14.         int daturaBomb = 0;//40
  15.         int cherryBomb = 0;//60
  16.         int smokeDecoyBomb = 0;//120
  17.         while (!bombEffect.isEmpty() && !bombCasing.isEmpty()) {
  18.             int currentBombEffect = bombEffect.peek();
  19.             int currentBombCasing = bombCasing.peek();
  20.  
  21.             if (currentBombEffect + currentBombCasing == 40) {
  22.                 daturaBomb++;
  23.                 checkForBomb(bombEffect, bombCasing);
  24.             } else if (currentBombEffect + currentBombCasing == 60) {
  25.                 cherryBomb++;
  26.                 checkForBomb(bombEffect, bombCasing);
  27.             } else if (currentBombEffect + currentBombCasing == 120) {
  28.                 smokeDecoyBomb++;
  29.                 checkForBomb(bombEffect, bombCasing);
  30.             } else {
  31.                 bombCasing.push(bombCasing.pop() - 5);
  32.             }
  33.             if (checkTheBombs(daturaBomb, cherryBomb, smokeDecoyBomb)) {
  34.                 break;
  35.             }
  36.         }
  37.         if (checkTheBombs(daturaBomb, cherryBomb, smokeDecoyBomb)) {
  38.             System.out.println("Bene! You have successfully filled the bomb pouch!");
  39.         } else {
  40.             System.out.println("You don't have enough materials to fill the bomb pouch.");
  41.         }
  42.  
  43.         if (!bombEffect.isEmpty()) {
  44.             printBombQueue(bombEffect);
  45.  
  46.         } else {
  47.             System.out.println("Bomb Effects: empty");
  48.         }
  49.  
  50.         if (!bombCasing.isEmpty()) {
  51.             printBombStack(bombCasing);
  52.  
  53.         } else {
  54.             System.out.println("Bomb Casings: empty");
  55.         }
  56.  
  57.         System.out.printf("Cherry Bombs: %d%n", cherryBomb);
  58.         System.out.printf("Datura Bombs: %d%n", daturaBomb);
  59.         System.out.printf("Smoke Decoy Bombs: %d%n", smokeDecoyBomb);
  60.     }
  61.  
  62.     private static void printBombStack(ArrayDeque<Integer> bomb) {
  63.         System.out.print("Bomb Casings: ");
  64.         StringBuilder sb = new StringBuilder();
  65.         for (int b : bomb) {
  66.             sb.append(bomb.pop());
  67.             if (!bomb.isEmpty()) {
  68.                 sb.append(", ");
  69.             }
  70.         }
  71.         System.out.println(sb.toString().trim());
  72.  
  73.     }
  74.  
  75.     private static void printBombQueue(ArrayDeque<Integer> bombEffect) {
  76.         System.out.print("Bomb Effects: ");
  77.         StringBuilder sb = new StringBuilder();
  78.         for (int bomb : bombEffect) {
  79.             sb.append(bombEffect.poll());
  80.             if (!bombEffect.isEmpty()) {
  81.                 sb.append(", ");
  82.             }
  83.         }
  84.         System.out.println(sb.toString().trim());
  85.     }
  86.  
  87.  
  88.     private static void checkForBomb(ArrayDeque<Integer> bombEffect, ArrayDeque<Integer> bombCasing) {
  89.         bombEffect.poll();
  90.         bombCasing.pop();
  91.     }
  92.  
  93.     private static boolean checkTheBombs(int daturaBomb, int cherryBomb, int smokeDecoyBomb) {
  94.         return daturaBomb >= 3 && cherryBomb >= 3 && smokeDecoyBomb >= 3;
  95.     }
  96.  
  97.     private static ArrayDeque<Integer> fillBombStack(Scanner scan) {
  98.         ArrayDeque<Integer> bomb = new ArrayDeque<>();
  99.         int[] arr = Arrays.stream(scan.nextLine().split(", "))
  100.                 .mapToInt(Integer::parseInt)
  101.                 .toArray();
  102.         for (int i : arr) {
  103.             bomb.push(i);
  104.         }
  105.  
  106.         return bomb;
  107.     }
  108.  
  109.  
  110.     private static ArrayDeque<Integer> fillBombQueue(Scanner scan) {
  111.         ArrayDeque<Integer> bomb = new ArrayDeque<>();
  112.         int[] arr = Arrays.stream(scan.nextLine().split(", "))
  113.                 .mapToInt(Integer::parseInt)
  114.                 .toArray();
  115.         for (int i : arr) {
  116.             bomb.offer(i);
  117.         }
  118.  
  119.         return bomb;
  120.     }
  121. }
  122.  
  123.  
Advertisement
Add Comment
Please, Sign In to add comment