Въпрос за задача "Autumn Cocktails"
Здравейте,С нулевите тестове всичко е наред, но с три от останалите не е така и не разбирам защо. Моля за съдействие, къде може да е проблема?
ЗАДАЧАТА
Summer is over, autumn has come. For this purpose, we have prepared several cocktails that we think you will like.
First, you will receive a sequence of integers, representing the number of ingredients in a single bucket. After that, you will be given another sequence of integers - the freshness level of the ingredients.
Your task is to mix them so you can produce the cocktails, listed in the table below with the exact freshness level.
Cocktail |
Freshness Level needed |
Pear Sour |
150 |
The Harvest |
250 |
Apple Hinny |
300 |
High Fashion |
400 |
To mix a cocktail, you have to take the first bucket of ingredients and the last freshness level value. The total freshness level is calculated by their multiplication. If the product of this operation equals one of the levels described in the table, you make the cocktail and remove both buckets with ingredients and freshness value. Otherwise, you should remove the freshness level, increase the ingredient value by 5, then remove it from the first position and add it at the end. In case you have an ingredient with a value of 0 you have to remove it and continue mixing the cocktails.
You need to stop making cocktails when you run out of buckets with ingredients or freshness level values.
Your task is considered done if you make at least four cocktails - one of each type.
Input
- The first line of input will represent the values of buckets with ingredients - integers, separated by a single space.
- On the second line, you will be given the freshness values - integers again, separated by a single space.
Output
- On the first line of output - print whether you've succeeded in preparing the cocktails
- "It's party time! The cocktails are ready!".
- "What a pity! You didn't manage to prepare all cocktails.".
- On the next output line - print the sum of the ingredients only if they are left any
- "Ingredients left: {sum of the left ingredients}".
- On the last few lines, you have to print the cocktails you have made at least once, ordered alphabetically in the format:
" # {cocktail name} --> {amount}".
Constraints
- All of the ingredients' values and freshness level values will be integers in the range [0, 100].
- We can have more than one mixed cocktail of the types specified in the table above.
Examples
Input |
Output |
Comment |
10 10 12 8 10 12 25 15 50 25 25 15 |
It's party time! The cocktails are ready! # Apple Hinny --> 2 # High Fashion --> 1 # Pear Sour --> 2 # The Harvest --> 1 |
First, you take the first ingredient and the last freshness level value and multiply them - the result is 150 so we make a Pear Sour cocktail. Next, we have a product of 250 and The Harvest cocktail is ready. Then we mix the Apple Hinny cocktail by multiplying 12 and 25. The product of next ingredient value and freshness level value is 400 and we make High Fashion cocktail. The next pair is 10 and 15, we multiply them and mix one more Pear Sour. The last multiplication of 12 and 25 equals 300 and we make one more Apple Hinny. There are no more ingredients and freshness values so we stop mixing cocktails, but we have one of each cocktail types and print the proper message. |
12 20 0 6 19 12 12 25 |
What a pity! You didn't manage to prepare all cocktails. Ingredients left: 55 # Apple Hinny --> 1 |
The first pair is 12 and 25, we mix the Apple Hinny cocktail and remove both of them. |
Това е кода ми:
package ExamPrep23October2021; import java.util.*; import java.util.stream.Collectors; public class P1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // ingredients - integers Queue // freshness values - integers Stack String[] ingredientsInput = scanner.nextLine().split("\\s+"); ArrayDeque<Integer> ingredients = new ArrayDeque<>(); for (String e : ingredientsInput) { int value = Integer.parseInt(e); ingredients.offer(value); } String[] freshnessInput = scanner.nextLine().split("\\s+"); ArrayDeque<Integer> freshness = new ArrayDeque<>(); for (String e : freshnessInput) { int value = Integer.parseInt(e); freshness.push(value); } Map<String, Integer> coctailsLevels = new LinkedHashMap<>(); coctailsLevels.put("Pear Sour", 150); coctailsLevels.put("The Harvest", 250); coctailsLevels.put("Apple Hinny", 300); coctailsLevels.put("High Fashion", 400); Map<String, Integer> coctailsquantity = new TreeMap<>(); while (!ingredients.isEmpty()&&!freshness.isEmpty()) { int a = ingredients.poll(); int b = freshness.pop(); int mix = a*b; String name = ""; for (Map.Entry<String, Integer> entry : coctailsLevels.entrySet()) { if (entry.getValue()==mix) { name = entry.getKey(); } } if (coctailsLevels.containsValue(mix)) { if (coctailsquantity.containsKey(name)) { int newQuantity = coctailsquantity.get(name) + 1; coctailsquantity.replace(name,newQuantity); } else { coctailsquantity.put(name,1); } } else { a = a+5; ingredients.offer(a); } } // System.out.println("A"); if (coctailsquantity.size()==4) { System.out.printf("It's party time! The cocktails are ready!%n"); for (Map.Entry<String, Integer> entry : coctailsquantity.entrySet()) { System.out.printf("# %s --> %d%n",entry.getKey(),entry.getValue()); } } else { System.out.printf("What a pity! You didn't manage to prepare all cocktails.%n"); int sum = 0; for (Integer element : ingredients) { sum = sum+element; } System.out.printf("Ingredients left: %d%n",sum); for (Map.Entry<String, Integer> entry : coctailsquantity.entrySet()) { System.out.printf("# %s --> %d%n",entry.getKey(),entry.getValue()); } } } }
Благодаря предварително.
Здравейте, колеги! И аз се нуждая от малко помощ относно тази задача. Два от тестовете не ми минават..
https://pastebin.com/Xu54RNxV -> Това е решението ми, какво ли не правих и пак не успявам.