Advertisement
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.*;
- public class MakeASalad {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String[] vegetables = reader.readLine().split("\\s+");
- ArrayDeque<String> queueVegetables = new ArrayDeque<>();
- for (String vegetable : vegetables) {
- queueVegetables.offer(vegetable);
- }
- int[] saladsCalories = Arrays.stream(reader.readLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
- ArrayDeque<Integer> stackSalads = new ArrayDeque<>();
- for (int salad : saladsCalories) {
- stackSalads.push(salad);
- }
- HashMap<String, Integer> vegetablesCalories = new HashMap<>();
- vegetablesCalories.put("tomato", 80);
- vegetablesCalories.put("carrot", 136);
- vegetablesCalories.put("lettuce", 109);
- vegetablesCalories.put("potato", 215);
- while (!queueVegetables.isEmpty() && !stackSalads.isEmpty()) {
- int currentSalad = stackSalads.peek();
- while (currentSalad > 0 && !queueVegetables.isEmpty()) {
- currentSalad -= vegetablesCalories.get(queueVegetables.poll());
- }
- System.out.print(stackSalads.pop() + " ");
- }
- System.out.println();
- if (!queueVegetables.isEmpty()) {
- System.out.println(String.join(" ", queueVegetables));
- }
- if (!stackSalads.isEmpty()) {
- for (Integer salad : stackSalads) {
- System.out.print(salad + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement