Advertisement
mirozspace

SpCr80_100

Jun 26th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3.  
  4. public class SpaceshipCrafting {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int countAluminium = 0;
  9.         int countCarbonFiber = 0;
  10.         int countGlass = 0;
  11.         int countLithium = 0;
  12.  
  13.         Deque<Integer> chemicalLiquids = Arrays.stream(scanner.nextLine().split("\\s+"))
  14.                 .mapToInt(Integer::parseInt)
  15.                 .boxed()
  16.                 .collect(Collectors.toCollection(ArrayDeque::new));
  17.  
  18.         Deque<Integer> physicalItems = new ArrayDeque<>();
  19.         Arrays.stream(scanner.nextLine().split("\\s+"))
  20.                 .mapToInt(Integer::parseInt)
  21.                 .forEach(physicalItems::push);
  22.  
  23.         while (!chemicalLiquids.isEmpty() && !physicalItems.isEmpty()) {
  24.             int currentLiquid = chemicalLiquids.peek();
  25.             int currentItem = physicalItems.peek();
  26.  
  27.             int temSum = currentLiquid + currentItem;
  28.             if (temSum == 25 || temSum == 50 || temSum == 75 || temSum == 100) {
  29.                 if (temSum == 25) {
  30.                     countGlass++;
  31.                 } else if (temSum == 50) {
  32.                     countAluminium++;
  33.                 } else if (temSum == 75) {
  34.                     countLithium++;
  35.                 } else {
  36.                     countCarbonFiber++;
  37.                 }
  38.                 chemicalLiquids.pop();
  39.                 physicalItems.remove();
  40.  
  41.             } else {
  42.                 chemicalLiquids.pop();
  43.                 int temValueItem = physicalItems.remove();
  44.                 temValueItem += 3;
  45.                 physicalItems.push(temValueItem);
  46.             }
  47.         }
  48.  
  49.         if (countAluminium > 0 && countCarbonFiber > 0 && countGlass > 0 && countLithium > 0) {
  50.             System.out.println("Wohoo! You succeeded in building the spaceship!");
  51.         } else {
  52.             System.out.println("Ugh, what a pity! You didn't have enough materials to build the spaceship.");
  53.         }
  54.  
  55.         //PRINT===
  56.  
  57.         if (!chemicalLiquids.isEmpty()) {
  58.             //ArrayList<Integer> chemicalLiquidsL = new ArrayList<>(chemicalLiquids);
  59.             String result = String.join(", ", chemicalLiquids + "");
  60.             result = result.substring(1, result.length() - 1);
  61.             System.out.println("Physical items left: " + result);
  62.         } else {
  63.             System.out.println("Liquids left: none");
  64.         }
  65.         if (!physicalItems.isEmpty()) {
  66.             String result = String.join(", ", physicalItems + "");
  67.             result = result.substring(1, result.length() - 1);
  68.             System.out.println("Physical items left: " + result);
  69.         } else {
  70.             System.out.println("Physical items left: none");
  71.         }
  72.  
  73.         System.out.println("Aluminium: " + countAluminium);
  74.         System.out.println("Carbon fiber: " + countCarbonFiber);
  75.         System.out.println("Glass: " + countGlass);
  76.         System.out.println("Lithium: " + countLithium);
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement