Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exam20200628;
- import com.sun.security.jgss.GSSUtil;
- import java.util.*;
- public class Bombs {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] line = Arrays.stream(scanner.nextLine().split(", "))
- .mapToInt(Integer::parseInt).toArray();
- ArrayDeque<Integer> queEffect = new ArrayDeque();
- for (int i = 0; i < line.length; i++) {
- queEffect.offer(line[i]);
- }
- line = Arrays.stream(scanner.nextLine().split(", "))
- .mapToInt(Integer::parseInt).toArray();
- ArrayDeque<Integer> staCasings = new ArrayDeque();
- for (int i = 0; i < line.length; i++) {
- staCasings.push(line[i]);
- }
- Map<String, Integer> bombs = new TreeMap<>();
- bombs.put("Datura Bombs", 0);
- bombs.put("Cherry Bombs", 0);
- bombs.put("Smoke Decoy Bombs", 0);
- boolean isFull = false;
- while (queEffect.size() > 0 && staCasings.size() > 0 && !isFull) {
- int effect = queEffect.peek();
- int casing = staCasings.peek();
- int result = effect + casing;
- while (result != 40 && result != 60 && result != 120) {
- result -= 5;
- }
- switch (result) {
- case 40:
- String currentBomb = "Datura Bombs";
- bombs.put(currentBomb, bombs.get(currentBomb) + 1);
- break;
- case 60:
- bombs.put("Cherry Bombs", bombs.get("Cherry Bombs") + 1);
- break;
- case 120:
- bombs.put("Smoke Decoy Bombs", bombs.get("Smoke Decoy Bombs") + 1);
- break;
- }
- if (bombs.get("Cherry Bombs") >= 3 && bombs.get("Datura Bombs") >= 3 && bombs.get("Smoke Decoy Bombs") >= 3) {
- isFull = true;
- }
- queEffect.poll();
- staCasings.pop();
- }
- if (isFull) {
- 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.");
- }
- StringBuilder builder = new StringBuilder();
- String output = queEffect.size() == 0 ? "Bomb Effects: empty" : "Bomb Effects: ";
- builder.append(output);
- for (Integer integer : queEffect) {
- builder.append(String.valueOf(integer));
- }
- System.out.println(String.join(", ", builder));
- builder = new StringBuilder();
- output = staCasings.size() == 0 ? "Bomb Casings: empty" : "Bomb Casings: ";
- builder.append(output);
- for (Integer integer : staCasings) {
- builder.append(String.valueOf(integer));
- }
- System.out.println(String.join(", ", builder));
- if (!bombs.isEmpty()) {
- bombs.entrySet().forEach(item ->
- System.out.printf("%s: %d%n", item.getKey(), item.getValue()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement