Advertisement
purshink

Santa Present Factory

Jun 27th, 2020
1,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.38 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.*;
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  12.         ArrayDeque<Integer> materialStack = new ArrayDeque<>();
  13.         ArrayDeque<Integer> magicValuesQueue = new ArrayDeque<>();
  14.         TreeMap<String, Integer> toys = new TreeMap<>();
  15.  
  16.         String[] b = bf.readLine().split(" ");
  17.         String[] m = bf.readLine().split(" ");
  18.  
  19.         for (String string : b) {
  20.             materialStack.push(Integer.parseInt(string));
  21.         }
  22.  
  23.         for (String string : m) {
  24.             magicValuesQueue.offer(Integer.parseInt(string));
  25.         }
  26.  
  27.  
  28.  
  29.  
  30.  
  31.         while (magicValuesQueue.size()>0 && materialStack.size()>0) {
  32.             int values = magicValuesQueue.peek();
  33.             int boxes = materialStack.peek();
  34.             int product = values * boxes;
  35.  
  36.             if (product < 0) {
  37.                 int result = values + boxes;
  38.                 magicValuesQueue.poll();
  39.                 materialStack.pop();
  40.                 materialStack.push(result);
  41.  
  42.             }
  43.             else if (boxes == 0 || values == 0) {
  44.                 if (boxes == 0) {
  45.                     materialStack.pop();
  46.                 }
  47.                 if (values == 0) {
  48.                     magicValuesQueue.poll();
  49.                 }
  50.  
  51.             }
  52.  
  53.             else if (product == 150 || product == 250 || product == 300 || product == 400) {
  54.                 String gift ;
  55.                 if (product == 150) {
  56.                     gift = "Doll";
  57.                     magicValuesQueue.poll();
  58.                     materialStack.pop();
  59.                     toys.putIfAbsent(gift, 0);
  60.                     toys.put(gift, toys.get(gift) + 1);
  61.                 } else if (product == 250) {
  62.                     gift = "Wooden train";
  63.                     magicValuesQueue.poll();
  64.                     materialStack.pop();
  65.                     toys.putIfAbsent(gift, 0);
  66.                     toys.put(gift, toys.get(gift) + 1);
  67.                 } else if (product == 300) {
  68.                     gift = "Teddy bear";
  69.                     magicValuesQueue.poll();
  70.                     materialStack.pop();
  71.                     toys.putIfAbsent(gift, 0);
  72.                     toys.put(gift, toys.get(gift) + 1);
  73.                 } else  {
  74.                     gift = "Bicycle";
  75.                     magicValuesQueue.poll();
  76.                     materialStack.pop();
  77.                     toys.putIfAbsent(gift, 0);
  78.                     toys.put(gift, toys.get(gift) + 1);
  79.                 }
  80.             }
  81.             else if (product>0) {
  82.                 magicValuesQueue.poll();
  83.                 boxes += 15;
  84.                 materialStack.pop();
  85.                 materialStack.push(boxes);
  86.             }
  87.         }
  88.  
  89.         if (toys.containsKey("Doll") && toys.containsKey("Wooden train")){
  90.             System.out.println("The presents are crafted! Merry Christmas!");
  91.         }
  92.         else if (toys.containsKey("Teddy bear") && toys.containsKey("Bicycle")){
  93.             System.out.println("The presents are crafted! Merry Christmas!");
  94.         }
  95.         else {
  96.             System.out.println("No presents this Christmas!");
  97.         }
  98.  
  99.         if (materialStack.size() > 0) {
  100.             System.out.print("Materials left: ");
  101.  
  102.             for (int i = 0; i < materialStack.size(); i++) {
  103.                 if (i == materialStack.size() - 1) {
  104.                     System.out.println(materialStack.pop());
  105.                 } else {
  106.                     System.out.print(materialStack.pop() + ", ");
  107.                     i--;
  108.                 }
  109.             }
  110.         }
  111.  
  112.         if (magicValuesQueue.size() > 0) {
  113.             System.out.print("Magic left: ");
  114.             for (int i = 0; i < magicValuesQueue.size(); i++) {
  115.                 if (i == magicValuesQueue.size() - 1) {
  116.                     System.out.println(magicValuesQueue.poll());
  117.                 } else {
  118.                     System.out.print(magicValuesQueue.poll() + ", ");
  119.                     i--;
  120.                 }
  121.             }
  122.         }
  123.  
  124.         for (Map.Entry<String, Integer> entry : toys.entrySet()) {
  125.             System.out.println(entry.getKey() + ": " + entry.getValue());
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement