borovaneca

Autumn Cocktails

May 31st, 2023
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.18 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6.  
  7. public class AutumnCocktails {
  8.  
  9.     private static final int PEAR_SOUR_AMOUNT = 150;
  10.     private static final int THE_HARVEST_AMOUNT = 250;
  11.     private static final int APPLE_HINNY_AMOUNT = 300;
  12.     private static final int HIGH_FASHION_AMOUNT = 400;
  13.  
  14.     private static final String PEAR_SOUR_NAME = "Pear Sour";
  15.     private static final String THE_HARVEST_NAME = "The Harvest";
  16.     private static final String APPLE_HINNY_NAME = "Apple Hinny";
  17.     private static final String HIGH_FASHION_NAME = "High Fashion";
  18.  
  19.     private static final Map<String, Integer> COCKTAILS = new LinkedHashMap<String, Integer>() {{
  20.         put(PEAR_SOUR_NAME, PEAR_SOUR_AMOUNT);
  21.         put(THE_HARVEST_NAME, THE_HARVEST_AMOUNT);
  22.         put(APPLE_HINNY_NAME, APPLE_HINNY_AMOUNT);
  23.         put(HIGH_FASHION_NAME, HIGH_FASHION_AMOUNT);
  24.     }};
  25.     public static void main(String[] args) throws IOException {
  26.  
  27.  
  28.         BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
  29.  
  30.  
  31.         ArrayDeque<Integer> ingredientsQueue = new ArrayDeque<>(Arrays.stream(scanner.readLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList()));
  32.         ArrayDeque<Integer> freshnessLevel = new ArrayDeque<>();
  33.         int[] inputIngredients = Arrays.stream(scanner.readLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
  34.         for (int inputIngredient : inputIngredients) {
  35.             freshnessLevel.push(inputIngredient);
  36.         }
  37.  
  38.         Map<String, Integer> succededCocktails = new LinkedHashMap<>();
  39.  
  40.  
  41.         while (!ingredientsQueue.isEmpty() && !freshnessLevel.isEmpty()) {
  42.  
  43.             int currentIngredient = ingredientsQueue.poll();
  44.             if (currentIngredient == 0) {
  45.                 continue;
  46.             }
  47.             int currentFreshLevel = freshnessLevel.pop();
  48.             int mix = currentIngredient * currentFreshLevel;
  49.             if (COCKTAILS.containsValue(mix)) {
  50.                 String name = "";
  51.                 for (Map.Entry<String, Integer> stringIntegerEntry : COCKTAILS.entrySet()) {
  52.                     if (stringIntegerEntry.getValue() == mix) {
  53.                         name = stringIntegerEntry.getKey();
  54.                     }
  55.                 }
  56.  
  57.                 succededCocktails.putIfAbsent(name, 0);
  58.                 succededCocktails.put(name, succededCocktails.get(name) + 1);
  59.             } else {
  60.                 ingredientsQueue.offer(currentIngredient + 5);
  61.             }
  62.  
  63.  
  64.         }
  65.  
  66.         if (succededCocktails.size() < 4) {
  67.             System.out.println("What a pity! You didn't manage to prepare all cocktails.");
  68.         } else {
  69.             System.out.println("It's party time! The cocktails are ready!");
  70.         }
  71.         if (!ingredientsQueue.isEmpty()) {
  72.             System.out.printf("Ingredients left: %d\n", ingredientsQueue.stream().mapToInt(i -> i).sum());
  73.         }
  74.  
  75.         succededCocktails.entrySet().stream().sorted(Map.Entry.comparingByKey())
  76.                 .forEach(key -> System.out.printf("# %s --> %d\n", key.getKey(),key.getValue()));
  77.     }
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment