Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 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 MakeASalad {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11.         //tomato - 80
  12.         // potato - 215
  13.         // carrot - 136
  14.         // lettuce - 109
  15.         // tomato - 80
  16.  
  17.         //250 563 478 330 470 112
  18.  
  19.         HashMap<String, Integer> vegetablesAndValues = new HashMap<>();
  20.         vegetablesAndValues.put("tomato", 80);
  21.         vegetablesAndValues.put("potato", 215);
  22.         vegetablesAndValues.put("carrot", 136);
  23.         vegetablesAndValues.put("lettuce", 109);
  24.  
  25.         List<String> vegetables = Arrays.stream(reader.readLine().split(" ")).collect(Collectors.toList());
  26.         Queue<String> queue = new LinkedList<>(vegetables);
  27.  
  28.         List<Integer> calorieValuesOfSalads = Arrays.stream(reader.readLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
  29.         Stack<Integer> stack = new Stack<>();
  30.         stack.addAll(calorieValuesOfSalads);
  31.  
  32.         List<Integer> readySalads = new ArrayList<>();
  33.         List<String> removedVegetables = new ArrayList<>();
  34.         List<Integer> unreadySalads = new ArrayList<>();
  35.  
  36.         while (!queue.isEmpty() && !stack.isEmpty()) {
  37.             String currentVegetable = queue.poll();
  38.             removedVegetables.add(currentVegetable);
  39.  
  40.             int currentVegetableValue = 0;
  41.             if (vegetablesAndValues.containsKey(currentVegetable)){
  42.                 currentVegetableValue = vegetablesAndValues.get(currentVegetable);
  43.             }
  44.  
  45.             int currentSaladCalories = stack.peek();
  46.             int result = currentSaladCalories - currentVegetableValue;
  47.             if (result <= 0){
  48.                 readySalads.add(stack.pop());
  49.             }
  50.         }
  51.  
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement