RGAlex

O2. Make a Salad.java/2019

Jun 20th, 2021
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3.  
  4. public class MakeASalad {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scan = new Scanner(System.in);
  9.         ArrayDeque<String> vegetables = Arrays.stream(scan.nextLine().split("\\s+"))
  10.                 .collect(Collectors.toCollection(ArrayDeque::new));
  11.         ArrayDeque<Integer> calories = new ArrayDeque<>();
  12.         Arrays.stream(scan.nextLine().split("\\s+")).mapToInt(Integer::parseInt).forEach(calories::push);
  13.         List<Integer>readySalad = new ArrayList<>();
  14.  
  15.         while (!vegetables.isEmpty() && !calories.isEmpty()) {
  16.             int valueOfSalad=calories.pop();
  17.             readySalad.add(valueOfSalad);
  18.             while (!vegetables.isEmpty()&&valueOfSalad>0){
  19.                 switch (vegetables.poll()){
  20.                     case "tomato":  valueOfSalad-=80 ; break;
  21.                     case "carrot":  valueOfSalad-=136; break;
  22.                     case "lettuce": valueOfSalad-=109; break;
  23.                     case "potato":  valueOfSalad-=215; break;
  24.                 }
  25.             }
  26.         }
  27.         System.out.println(readySalad.stream().map(String::valueOf).collect(Collectors.joining(" ")));
  28.         if(!vegetables.isEmpty()){
  29.             System.out.println(vegetables.stream().map(String::valueOf).collect(Collectors.joining(" ")));
  30.         }
  31.         if(!calories.isEmpty()){
  32.             System.out.println(calories.stream().map(String::valueOf).collect(Collectors.joining(" ")));
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment