Advertisement
Andreeva-Magdalena97

Spaceship

Oct 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.59 KB | None | 0 0
  1. package EX1702;
  2.  
  3. import java.util.*;
  4. import java.util.Map;
  5. import java.util.stream.Collectors;
  6.  
  7. public class Spaceship {
  8.     public static void main(String[] args) {
  9.         Scanner s = new Scanner(System.in);
  10.  
  11.         int[] first = Arrays.stream(s.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  12.         int[] second = Arrays.stream(s.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  13.         Stack<Integer> stack = new Stack<>();
  14.         Queue<Integer> opashka = new LinkedList<>();
  15.         Map<String, Integer> map = new TreeMap<>();
  16.         map.put("Glass", 0);
  17.         map.put("Aluminium", 0);
  18.         map.put("Lithium", 0);
  19.         map.put("Carbon fiber", 0);
  20.         for (int i = 0; i < first.length; i++) {
  21.             opashka.offer(first[i]);
  22.         }
  23.         for (int i = 0; i < second.length; i++) {
  24.             stack.add(second[i]);
  25.         }
  26.         while (opashka.size() > 0){
  27.             if (stack.size() == 0){
  28.                 break;
  29.             }else {
  30.                 int number = opashka.peek();
  31.                 int numberTWO = stack.peek();
  32.                 int result = number + numberTWO;
  33.                 if (result == 25){
  34.                     String com = "Glass";
  35.                      int num = map.get(com) + 1;
  36.                      map.put(com, num);
  37.                     opashka.poll();
  38.                     stack.pop();
  39.                 }else if (result == 50){
  40.                     String com = "Aluminium";
  41.                         int num = map.get(com) + 1;
  42.                         map.put(com, num);
  43.                     opashka.poll();
  44.                     stack.pop();
  45.                 }else if (result == 75){
  46.                     String com = "Lithium";
  47.                         int num = map.get(com) + 1;
  48.                         map.put(com, num);
  49.                     opashka.poll();
  50.                     stack.pop();
  51.                 }else if (result == 100){
  52.                     String com = "Carbon fiber";
  53.                         int num = map.get(com) + 1;
  54.                         map.put(com, num);
  55.                     opashka.poll();
  56.                     stack.pop();
  57.                 }else {
  58.                     opashka.poll();
  59.                     int newNum = stack.pop() + 3;
  60.                      stack.push(newNum);
  61.                 }
  62.  
  63.             }
  64.         }
  65.        boolean isTrue = true;
  66.         for (Map.Entry<String, Integer> entry : map.entrySet()) {
  67.             if (entry.getValue() == 0){
  68.                 isTrue = false;
  69.             }
  70.         }
  71.         if (isTrue) {
  72.             System.out.println("Wohoo! You succeeded in building the spaceship!");
  73.         }
  74.         else {
  75.             System.out.println("Ugh, what a pity! You didn't have enough materials to build the spaceship.");
  76.         }
  77.         List<Integer> list = new ArrayList<>();
  78.         if (opashka.size() > 0){
  79.             list.addAll(opashka);
  80.             System.out.println("Liquids left: " + list.stream().map(String::valueOf).collect(Collectors.joining(", ")));
  81.             list.clear();
  82.         }else {
  83.             System.out.println("Liquids left: none");
  84.         }
  85.         if (stack.size() > 0){
  86.             list.addAll(stack);
  87.             Collections.reverse(list);
  88.             System.out.println("Physical items left: " + list.stream().map(String::valueOf).collect(Collectors.joining(", ")));
  89.             list.clear();
  90.         }else {
  91.             System.out.println("Physical items left: none");
  92.         }
  93.         map.entrySet().stream().forEach(e -> {
  94.             System.out.println(e.getKey() + ": " + e.getValue());
  95.         });
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement