Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //!!!90/100
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- public class _02_ {
- public static void main(String[] args) throws IOException {
- int tomatoMax = 80;
- int carrotMax = 136;
- int lettuceMax = 109;
- int potatoMax = 215;
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String[] v = reader.readLine().split(" ");
- int[] c = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- ArrayDeque<String> vegetables = new ArrayDeque<>(); //q
- ArrayDeque<Integer> saladCalories = new ArrayDeque<>(); //s
- for (String veg : v) {
- vegetables.offer(veg);
- }
- for (Integer cal : c) {
- saladCalories.push(cal);
- }
- // //queue:
- // ArrayDeque<String> vegetables = new ArrayDeque<>();
- // Arrays.stream(v
- // .split(" "))
- // .forEach(vegetables::offer);
- //
- // //stack:
- // ArrayDeque<Integer> saladCalories = new ArrayDeque<>();
- // Arrays.stream(c
- // .split(" "))
- // .map(Integer::parseInt)
- // .forEach(saladCalories::push);
- ArrayDeque<Integer> saladResult = new ArrayDeque<>(); //q
- while (!vegetables.isEmpty() && !saladCalories.isEmpty()) {
- //saladCal:
- int amount = saladCalories.peek();
- String veg = vegetables.poll();
- switch (veg) {
- case "tomato":
- amount -= tomatoMax;
- if (amount <= 0) {
- saladResult.offer(saladCalories.pop());
- break;
- }
- break;
- case "carrot":
- amount -= carrotMax;
- if (amount <= 0) {
- saladResult.offer(saladCalories.pop());
- break;
- }
- break;
- case "lettuce":
- amount -= lettuceMax;
- if (amount <= 0) {
- saladResult.offer(saladCalories.pop());
- break;
- }
- break;
- case "potato":
- amount -= potatoMax;
- if (amount <= 0) {
- saladResult.offer(saladCalories.pop());
- break;
- }
- break;
- }
- if (vegetables.isEmpty() && amount > 0) {
- saladResult.offer(saladCalories.pop());
- break;
- }
- }
- if (!saladResult.isEmpty()) {
- while (!saladResult.isEmpty()) {
- System.out.print(saladResult.poll() + " ");
- }
- System.out.println();
- }
- if (!vegetables.isEmpty()) {
- while (!vegetables.isEmpty()) {
- System.out.print(vegetables.poll() + " ");
- }
- System.out.println();
- }
- if (!saladCalories.isEmpty()) {
- while (!saladCalories.isEmpty()) {
- System.out.print(saladCalories.poll() + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement