SophiYo

MakeASalad

Jun 19th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Arrays;
  5. import java.util.Deque;
  6. import java.util.Scanner;
  7.  
  8. public class MakeASalad {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         String[] a = scanner.nextLine().split("\\s+");
  13.         ArrayDeque<String> products = new ArrayDeque<>();
  14.         ArrayDeque<Integer> salads = new ArrayDeque<>();
  15.         ArrayDeque<Integer> makedSalad = new ArrayDeque<>();
  16.  
  17.         products.addAll(Arrays.asList(a));
  18.  
  19.         String[] b = scanner.nextLine().split("\\s+");
  20.         for (int i = 0; i < b.length; i++) {
  21.             int c = Integer.parseInt(b[i]);
  22.             salads.push(c);
  23.         }
  24.  
  25.         while (!products.isEmpty() && !salads.isEmpty()){
  26.             int calorie = salads.pop();
  27.             makedSalad.add(calorie);
  28.  
  29.             while (calorie > 0 && !products.isEmpty()){
  30.                 String vegetable = products.poll();
  31.                 if (vegetable.equals("tomato")){
  32.                     calorie -= 80;
  33.  
  34.                 }else if (vegetable.equals("potato")){
  35.                     calorie -= 215;
  36.  
  37.                 }else if (vegetable.equals("carrot")){
  38.                     calorie -= 136;
  39.  
  40.                 }else if (vegetable.equals("lettuce")){
  41.                     calorie -= 109;
  42.                 }
  43.             }
  44.         }
  45.  
  46.         if (!makedSalad.isEmpty()){
  47.             for (Integer j: makedSalad) {
  48.                 System.out.printf("%d ", j);
  49.             }
  50.             System.out.println();
  51.         }
  52.  
  53.         if (!salads.isEmpty()){
  54.             for (Integer j: salads) {
  55.                 System.out.printf("%d ", j);
  56.             }
  57.             System.out.println();
  58.         }
  59.  
  60.         if (!products.isEmpty()){
  61.             for (String j: products) {
  62.                 System.out.printf("%s ", j);
  63.             }
  64.             System.out.println();
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment