Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exam;
- import java.util.*;
- public class AutumnCocktails {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] bucketString = scanner.nextLine().split("\\s+");
- String[] freshnessString = scanner.nextLine().split("\\s+");
- ArrayDeque<Integer> bucketValues = new ArrayDeque<>();
- Stack<Integer> freshnessValues = new Stack<>();
- Map<String, Integer> createdCocktails = new TreeMap<>();
- createdCocktails.put("High Fashion", 0);
- createdCocktails.put("Apple Hinny", 0);
- createdCocktails.put("The Harvest", 0);
- createdCocktails.put("Pear Sour", 0);
- Arrays.stream(bucketString).mapToInt(Integer::parseInt).forEach(bucketValues::offer);
- Arrays.stream(freshnessString).mapToInt(Integer::parseInt).forEach(freshnessValues::push);
- while (!bucketValues.isEmpty() || !freshnessValues.isEmpty()) {
- if (bucketValues.isEmpty() || freshnessValues.isEmpty()) {
- break;
- }
- int element1 = bucketValues.peek();
- int element2 = freshnessValues.peek();
- int localProd = element1 * element2;
- if (localProd == 150) {
- createdCocktails.put("Pear Sour", createdCocktails.get("Pear Sour") + 1);
- bucketValues.poll();
- freshnessValues.pop();
- } else if (localProd == 250) {
- createdCocktails.put("The Harvest", createdCocktails.get("The Harvest") + 1);
- bucketValues.poll();
- freshnessValues.pop();
- } else if (localProd == 300) {
- createdCocktails.put("Apple Hinny", createdCocktails.get("Apple Hinny") + 1);
- bucketValues.poll();
- freshnessValues.pop();
- } else if (localProd == 400) {
- createdCocktails.put("High Fashion", createdCocktails.get("High Fashion") + 1);
- bucketValues.poll();
- freshnessValues.pop();
- } else if (bucketValues.peek() == 0) {
- bucketValues.poll();
- } else {
- freshnessValues.pop();
- bucketValues.offerLast(bucketValues.poll() + 5);
- }
- }
- if (createdCocktails.containsValue(0)) {
- System.out.println("What a pity! You didn't manage to prepare all cocktails.");
- } else {
- System.out.println("It's party time! The cocktails are ready!");
- }
- int sum = bucketValues.stream().mapToInt(e -> e).sum();
- if (sum > 0) {
- System.out.printf("Ingredients left: %d%n", sum);
- }
- for (Map.Entry<String, Integer> entry : createdCocktails.entrySet()) {
- if (entry.getValue() > 0) {
- System.out.printf("# %s --> %d%n", entry.getKey(), entry.getValue());
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment