Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5.  
  6. public class MakeASalad {
  7.     public static void main(String[] args) throws IOException {
  8.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  9.  
  10.         String[] vegetables = reader.readLine().split("\\s+");
  11.         ArrayDeque<String> queueVegetables = new ArrayDeque<>();
  12.         for (String vegetable : vegetables) {
  13.             queueVegetables.offer(vegetable);
  14.         }
  15.  
  16.         int[] saladsCalories = Arrays.stream(reader.readLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
  17.         ArrayDeque<Integer> stackSalads = new ArrayDeque<>();
  18.         for (int salad : saladsCalories) {
  19.             stackSalads.push(salad);
  20.         }
  21.  
  22.         HashMap<String, Integer> vegetablesCalories = new HashMap<>();
  23.         vegetablesCalories.put("tomato", 80);
  24.         vegetablesCalories.put("carrot", 136);
  25.         vegetablesCalories.put("lettuce", 109);
  26.         vegetablesCalories.put("potato", 215);
  27.  
  28.         while (!queueVegetables.isEmpty() && !stackSalads.isEmpty()) {
  29.             int currentSalad = stackSalads.peek();
  30.  
  31.             while (currentSalad > 0 && !queueVegetables.isEmpty()) {
  32.                 currentSalad -= vegetablesCalories.get(queueVegetables.poll());
  33.             }
  34.             System.out.print(stackSalads.pop() + " ");
  35.         }
  36.         System.out.println();
  37.  
  38.         if (!queueVegetables.isEmpty()) {
  39.             System.out.println(String.join(" ", queueVegetables));
  40.         }
  41.  
  42.         if (!stackSalads.isEmpty()) {
  43.             for (Integer salad : stackSalads) {
  44.                 System.out.print(salad + " ");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement