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.*;
- import java.util.stream.Collectors;
- public class MakeASalad {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- //tomato - 80
- // potato - 215
- // carrot - 136
- // lettuce - 109
- // tomato - 80
- //250 563 478 330 470 112
- HashMap<String, Integer> vegetablesAndValues = new HashMap<>();
- vegetablesAndValues.put("tomato", 80);
- vegetablesAndValues.put("potato", 215);
- vegetablesAndValues.put("carrot", 136);
- vegetablesAndValues.put("lettuce", 109);
- List<String> vegetables = Arrays.stream(reader.readLine().split(" ")).collect(Collectors.toList());
- Queue<String> queue = new LinkedList<>(vegetables);
- List<Integer> calorieValuesOfSalads = Arrays.stream(reader.readLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
- Stack<Integer> stack = new Stack<>();
- stack.addAll(calorieValuesOfSalads);
- List<Integer> readySalads = new ArrayList<>();
- List<String> removedVegetables = new ArrayList<>();
- List<Integer> unreadySalads = new ArrayList<>();
- while (!queue.isEmpty() && !stack.isEmpty()) {
- String currentVegetable = queue.poll();
- removedVegetables.add(currentVegetable);
- int currentVegetableValue = 0;
- if (vegetablesAndValues.containsKey(currentVegetable)){
- currentVegetableValue = vegetablesAndValues.get(currentVegetable);
- }
- int currentSaladCalories = stack.peek();
- int result = currentSaladCalories - currentVegetableValue;
- if (result <= 0){
- readySalads.add(stack.pop());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement