Advertisement
damesova

2

Jun 20th, 2019
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. //!!!90/100
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.*;
  7.  
  8. public class _02_ {
  9.     public static void main(String[] args) throws IOException {
  10.  
  11.         int tomatoMax = 80;
  12.         int carrotMax = 136;
  13.         int lettuceMax = 109;
  14.         int potatoMax = 215;
  15.  
  16.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  17.         String[] v = reader.readLine().split(" ");
  18.         int[] c = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  19.  
  20.  
  21.         ArrayDeque<String> vegetables = new ArrayDeque<>(); //q
  22.         ArrayDeque<Integer> saladCalories = new ArrayDeque<>(); //s
  23.  
  24.         for (String veg : v) {
  25.             vegetables.offer(veg);
  26.         }
  27.  
  28.         for (Integer cal : c) {
  29.             saladCalories.push(cal);
  30.         }
  31.  
  32. //        //queue:
  33. //        ArrayDeque<String> vegetables = new ArrayDeque<>();
  34. //        Arrays.stream(v
  35. //                .split(" "))
  36. //                .forEach(vegetables::offer);
  37. //
  38. //        //stack:
  39. //        ArrayDeque<Integer> saladCalories = new ArrayDeque<>();
  40. //        Arrays.stream(c
  41. //                .split(" "))
  42. //                .map(Integer::parseInt)
  43. //                .forEach(saladCalories::push);
  44.  
  45.  
  46.         ArrayDeque<Integer> saladResult = new ArrayDeque<>(); //q
  47.  
  48.         while (!vegetables.isEmpty() && !saladCalories.isEmpty()) {
  49.             //saladCal:
  50.             int amount = saladCalories.peek();
  51.  
  52.             String veg = vegetables.poll();
  53.             switch (veg) {
  54.                 case "tomato":
  55.                     amount -= tomatoMax;
  56.                     if (amount <= 0) {
  57.                         saladResult.offer(saladCalories.pop());
  58.                         break;
  59.                     }
  60.                     break;
  61.                 case "carrot":
  62.                     amount -= carrotMax;
  63.                     if (amount <= 0) {
  64.                         saladResult.offer(saladCalories.pop());
  65.                         break;
  66.                     }
  67.                     break;
  68.                 case "lettuce":
  69.                     amount -= lettuceMax;
  70.                     if (amount <= 0) {
  71.                         saladResult.offer(saladCalories.pop());
  72.                         break;
  73.                     }
  74.                     break;
  75.                 case "potato":
  76.                     amount -= potatoMax;
  77.                     if (amount <= 0) {
  78.                         saladResult.offer(saladCalories.pop());
  79.                         break;
  80.                     }
  81.                     break;
  82.             }
  83.  
  84.             if (vegetables.isEmpty() && amount > 0) {
  85.                 saladResult.offer(saladCalories.pop());
  86.                 break;
  87.             }
  88.         }
  89.  
  90.  
  91.         if (!saladResult.isEmpty()) {
  92.             while (!saladResult.isEmpty()) {
  93.                 System.out.print(saladResult.poll() + " ");
  94.             }
  95.             System.out.println();
  96.         }
  97.         if (!vegetables.isEmpty()) {
  98.             while (!vegetables.isEmpty()) {
  99.                 System.out.print(vegetables.poll() + " ");
  100.             }
  101.             System.out.println();
  102.         }
  103.  
  104.         if (!saladCalories.isEmpty()) {
  105.             while (!saladCalories.isEmpty()) {
  106.                 System.out.print(saladCalories.poll() + " ");
  107.             }
  108.             System.out.println();
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement