Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.stream.Collectors;
- public class SpaceshipCrafting {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int countAluminium = 0;
- int countCarbonFiber = 0;
- int countGlass = 0;
- int countLithium = 0;
- Deque<Integer> chemicalLiquids = Arrays.stream(scanner.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt)
- .boxed()
- .collect(Collectors.toCollection(ArrayDeque::new));
- Deque<Integer> physicalItems = new ArrayDeque<>();
- Arrays.stream(scanner.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt)
- .forEach(physicalItems::push);
- while (!chemicalLiquids.isEmpty() && !physicalItems.isEmpty()) {
- int currentLiquid = chemicalLiquids.peek();
- int currentItem = physicalItems.peek();
- int temSum = currentLiquid + currentItem;
- if (temSum == 25 || temSum == 50 || temSum == 75 || temSum == 100) {
- if (temSum == 25) {
- countGlass++;
- } else if (temSum == 50) {
- countAluminium++;
- } else if (temSum == 75) {
- countLithium++;
- } else {
- countCarbonFiber++;
- }
- chemicalLiquids.pop();
- physicalItems.remove();
- } else {
- chemicalLiquids.pop();
- int temValueItem = physicalItems.remove();
- temValueItem += 3;
- physicalItems.push(temValueItem);
- }
- }
- if (countAluminium > 0 && countCarbonFiber > 0 && countGlass > 0 && countLithium > 0) {
- 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.");
- }
- //PRINT===
- if (!chemicalLiquids.isEmpty()) {
- //ArrayList<Integer> chemicalLiquidsL = new ArrayList<>(chemicalLiquids);
- String result = String.join(", ", chemicalLiquids + "");
- result = result.substring(1, result.length() - 1);
- System.out.println("Physical items left: " + result);
- } else {
- System.out.println("Liquids left: none");
- }
- if (!physicalItems.isEmpty()) {
- String result = String.join(", ", physicalItems + "");
- result = result.substring(1, result.length() - 1);
- System.out.println("Physical items left: " + result);
- } else {
- System.out.println("Physical items left: none");
- }
- System.out.println("Aluminium: " + countAluminium);
- System.out.println("Carbon fiber: " + countCarbonFiber);
- System.out.println("Glass: " + countGlass);
- System.out.println("Lithium: " + countLithium);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement