Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package EX1702;
- import java.util.*;
- import java.util.Map;
- import java.util.stream.Collectors;
- public class Spaceship {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- int[] first = Arrays.stream(s.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- int[] second = Arrays.stream(s.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- Stack<Integer> stack = new Stack<>();
- Queue<Integer> opashka = new LinkedList<>();
- Map<String, Integer> map = new TreeMap<>();
- map.put("Glass", 0);
- map.put("Aluminium", 0);
- map.put("Lithium", 0);
- map.put("Carbon fiber", 0);
- for (int i = 0; i < first.length; i++) {
- opashka.offer(first[i]);
- }
- for (int i = 0; i < second.length; i++) {
- stack.add(second[i]);
- }
- while (opashka.size() > 0){
- if (stack.size() == 0){
- break;
- }else {
- int number = opashka.peek();
- int numberTWO = stack.peek();
- int result = number + numberTWO;
- if (result == 25){
- String com = "Glass";
- int num = map.get(com) + 1;
- map.put(com, num);
- opashka.poll();
- stack.pop();
- }else if (result == 50){
- String com = "Aluminium";
- int num = map.get(com) + 1;
- map.put(com, num);
- opashka.poll();
- stack.pop();
- }else if (result == 75){
- String com = "Lithium";
- int num = map.get(com) + 1;
- map.put(com, num);
- opashka.poll();
- stack.pop();
- }else if (result == 100){
- String com = "Carbon fiber";
- int num = map.get(com) + 1;
- map.put(com, num);
- opashka.poll();
- stack.pop();
- }else {
- opashka.poll();
- int newNum = stack.pop() + 3;
- stack.push(newNum);
- }
- }
- }
- boolean isTrue = true;
- for (Map.Entry<String, Integer> entry : map.entrySet()) {
- if (entry.getValue() == 0){
- isTrue = false;
- }
- }
- if (isTrue) {
- System.out.println("Wohoo! You succeeded in building the spaceship!");
- }
- else {
- System.out.println("Ugh, what a pity! You didn't have enough materials to build the spaceship.");
- }
- List<Integer> list = new ArrayList<>();
- if (opashka.size() > 0){
- list.addAll(opashka);
- System.out.println("Liquids left: " + list.stream().map(String::valueOf).collect(Collectors.joining(", ")));
- list.clear();
- }else {
- System.out.println("Liquids left: none");
- }
- if (stack.size() > 0){
- list.addAll(stack);
- Collections.reverse(list);
- System.out.println("Physical items left: " + list.stream().map(String::valueOf).collect(Collectors.joining(", ")));
- list.clear();
- }else {
- System.out.println("Physical items left: none");
- }
- map.entrySet().stream().forEach(e -> {
- System.out.println(e.getKey() + ": " + e.getValue());
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement