Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaAdvancedExam28June2020;
- import java.util.ArrayDeque;
- import java.util.Arrays;
- import java.util.Scanner;
- public class P01Bombs {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int[] arr1 = Arrays.stream(sc.nextLine().split(", "))
- .mapToInt(Integer::parseInt)
- .toArray();
- ArrayDeque<Integer> queue = new ArrayDeque<>();
- for (int i = 0; i < arr1.length; i++) {
- queue.offer(arr1[i]);
- }
- int[] arr2 = Arrays.stream(sc.nextLine().split(", "))
- .mapToInt(Integer::parseInt)
- .toArray();
- ArrayDeque<Integer> stack = new ArrayDeque<>();
- for (int i = 0; i < arr2.length; i++) {
- stack.push(arr2[i]);
- }
- int daturaBomb = 40;
- int cherryBomb = 60;
- int smokeDecoyBomb = 120;
- int daturaCount = 0;
- int cherryCount = 0;
- int smoDecoyCount = 0;
- int firstEl = 0;
- int lastEl = 0;
- int sum = 0;
- while (true) {
- if (stack.isEmpty() || queue.isEmpty()) {
- break;
- }
- firstEl = queue.peek();
- lastEl = stack.peek();
- sum = firstEl + lastEl;
- if (sum == daturaBomb) {
- queue.poll();
- stack.pop();
- daturaCount++;
- } else if (sum == cherryBomb) {
- queue.poll();
- stack.pop();
- cherryCount++;
- } else if (sum == smokeDecoyBomb) {
- queue.pop();
- stack.pop();
- smoDecoyCount++;
- } else {
- lastEl -= 5;
- stack.pop();
- stack.push(lastEl);
- sum = 0;
- }
- }
- if (smoDecoyCount == 3 && cherryCount == 3 && daturaCount == 3) {
- System.out.println("Bene! You have successfully filled the bomb pouch!");
- } else {
- System.out.println("You don't have enough materials to fill the bomb pouch.");
- }
- if (queue.isEmpty()) {
- System.out.println("Bomb Effects: empty");
- } else {
- System.out.print("Bomb Effects: ");
- queue.forEach(System.out::print);
- }
- if (stack.isEmpty()) {
- System.out.println("Bomb Casings: empty");
- } else {
- System.out.print("Bomb Casings: ");
- for (Integer integer : stack) {
- System.out.print(integer + " ");
- }
- }
- System.out.println(cherryCount);
- System.out.println(daturaCount);
- System.out.println(smoDecoyCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement