Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- import java.util.stream.Collectors;
- public class AutumnCocktails {
- private static final int PEAR_SOUR_AMOUNT = 150;
- private static final int THE_HARVEST_AMOUNT = 250;
- private static final int APPLE_HINNY_AMOUNT = 300;
- private static final int HIGH_FASHION_AMOUNT = 400;
- private static final String PEAR_SOUR_NAME = "Pear Sour";
- private static final String THE_HARVEST_NAME = "The Harvest";
- private static final String APPLE_HINNY_NAME = "Apple Hinny";
- private static final String HIGH_FASHION_NAME = "High Fashion";
- private static final Map<String, Integer> COCKTAILS = new LinkedHashMap<String, Integer>() {{
- put(PEAR_SOUR_NAME, PEAR_SOUR_AMOUNT);
- put(THE_HARVEST_NAME, THE_HARVEST_AMOUNT);
- put(APPLE_HINNY_NAME, APPLE_HINNY_AMOUNT);
- put(HIGH_FASHION_NAME, HIGH_FASHION_AMOUNT);
- }};
- public static void main(String[] args) throws IOException {
- BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
- ArrayDeque<Integer> ingredientsQueue = new ArrayDeque<>(Arrays.stream(scanner.readLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList()));
- ArrayDeque<Integer> freshnessLevel = new ArrayDeque<>();
- int[] inputIngredients = Arrays.stream(scanner.readLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
- for (int inputIngredient : inputIngredients) {
- freshnessLevel.push(inputIngredient);
- }
- Map<String, Integer> succededCocktails = new LinkedHashMap<>();
- while (!ingredientsQueue.isEmpty() && !freshnessLevel.isEmpty()) {
- int currentIngredient = ingredientsQueue.poll();
- if (currentIngredient == 0) {
- continue;
- }
- int currentFreshLevel = freshnessLevel.pop();
- int mix = currentIngredient * currentFreshLevel;
- if (COCKTAILS.containsValue(mix)) {
- String name = "";
- for (Map.Entry<String, Integer> stringIntegerEntry : COCKTAILS.entrySet()) {
- if (stringIntegerEntry.getValue() == mix) {
- name = stringIntegerEntry.getKey();
- }
- }
- succededCocktails.putIfAbsent(name, 0);
- succededCocktails.put(name, succededCocktails.get(name) + 1);
- } else {
- ingredientsQueue.offer(currentIngredient + 5);
- }
- }
- if (succededCocktails.size() < 4) {
- 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!");
- }
- if (!ingredientsQueue.isEmpty()) {
- System.out.printf("Ingredients left: %d\n", ingredientsQueue.stream().mapToInt(i -> i).sum());
- }
- succededCocktails.entrySet().stream().sorted(Map.Entry.comparingByKey())
- .forEach(key -> System.out.printf("# %s --> %d\n", key.getKey(),key.getValue()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment