Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package spaceStationRecruitment;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- private final static int GLASS = 25;
- private final static int ALUMINIUM = 50;
- private final static int LITHIUM = 75;
- private final static int CARBON_FIBER = 100;
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> input = getInput(scanner);
- Deque<Integer> chemicalLiquids = new ArrayDeque<>(input);
- input = getInput(scanner);
- Collections.reverse(input);
- Deque<Integer> physicalItems = new ArrayDeque<>(input);
- Map<String, Integer> advancedMaterialReached = new LinkedHashMap<>();
- advancedMaterialReached.put("Aluminium", 0);
- advancedMaterialReached.put("Carbon fiber", 0);
- advancedMaterialReached.put("Glass", 0);
- advancedMaterialReached.put("Lithium", 0);
- boolean glassReached = false;
- boolean aluminiumReached = false;
- boolean lithiumReached = false;
- boolean carbonFiberReached = false;
- while (!chemicalLiquids.isEmpty() && !physicalItems.isEmpty()) {
- int currentLiquid = chemicalLiquids.pollFirst();
- int currentItem = physicalItems.pop();
- int sumOfReaction = currentLiquid + currentItem;
- if (sumOfReaction == GLASS) {
- advancedMaterialReached.put("Glass", advancedMaterialReached.get("Glass") + 1);
- glassReached = true;
- } else if (sumOfReaction == ALUMINIUM) {
- advancedMaterialReached.put("Aluminium", advancedMaterialReached.get("Aluminium") + 1);
- aluminiumReached = true;
- } else if (sumOfReaction == LITHIUM) {
- advancedMaterialReached.put("Lithium", advancedMaterialReached.get("Lithium") + 1);
- lithiumReached = true;
- } else if (sumOfReaction == CARBON_FIBER) {
- advancedMaterialReached.put("Carbon fiber", advancedMaterialReached.get("Carbon fiber") + 1);
- carbonFiberReached = true;
- } else {
- currentItem += 3;
- physicalItems.push(currentItem);
- }
- }
- StringBuilder output = new StringBuilder();
- if (glassReached && aluminiumReached && lithiumReached && carbonFiberReached) {
- output.append("Wohoo! You succeeded in building the spaceship!")
- .append(System.lineSeparator());
- } else {
- output.append("Ugh, what a pity! You didn't have enough materials to build the spaceship.")
- .append(System.lineSeparator());
- }
- if (chemicalLiquids.isEmpty()) {
- output.append("Liquids left: none")
- .append(System.lineSeparator());
- } else {
- output.append("Liquids left: ");
- while (!chemicalLiquids.isEmpty()) {
- output.append(chemicalLiquids.poll());
- output.append(", ");
- }
- output.delete(output.length() - 2, output.length() - 1).append(System.lineSeparator());
- }
- if (physicalItems.isEmpty()) {
- output.append("Physical items left: none").append(System.lineSeparator());
- } else {
- output.append("Physical items left: ");
- while (!physicalItems.isEmpty()) {
- output.append(physicalItems.pop());
- output.append(", ");
- }
- output.delete(output.length() - 2, output.length() - 1).append(System.lineSeparator());
- }
- for (Map.Entry<String, Integer> entry : advancedMaterialReached.entrySet()) {
- output.append(entry.getKey()).append(": ").append(entry.getValue()).append(System.lineSeparator());
- }
- System.out.println(output.toString());
- }
- private static List<Integer> getInput(Scanner scanner) {
- return Arrays.stream(scanner.nextLine().split("\\s")).map(Integer::parseInt).collect(Collectors.toList());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement