Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayDeque;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- public class TempleOfDoom {
- public static void main(String[] args) throws IOException {
- BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
- ArrayDeque<Integer> tools = new ArrayDeque<>(Arrays.stream(scanner.readLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList()));
- ArrayDeque<Integer> substances = new ArrayDeque<>();
- Arrays.stream(scanner.readLine().split("\\s+")).map(Integer::parseInt).forEach(substances::push);
- List<String> challenges = Arrays.stream(scanner.readLine().split("\\s+")).collect(Collectors.toList());
- while (!tools.isEmpty() && !substances.isEmpty()) {
- int currentTool = tools.poll();
- int currentSubstance = substances.pop();
- int sum = currentSubstance * currentTool;
- if (challenges.contains(String.valueOf(sum))) {
- challenges.remove(String.valueOf(sum));
- } else {
- tools.offer(currentTool + 1);
- currentSubstance--;
- if (currentSubstance > 0) {
- substances.push(currentSubstance);
- }
- }
- }
- if (!challenges.isEmpty() && tools.isEmpty() || !challenges.isEmpty() && substances.isEmpty()) {
- System.out.println("Harry is lost in the temple. Oblivion awaits him.");
- } else {
- System.out.println("Harry found an ostracon, which is dated to the 6th century BCE.");
- }
- if (!tools.isEmpty()) {
- System.out.printf("Tools: %s\n", String.join(", ", tools.stream().map(String::valueOf).collect(Collectors.toList())));
- }
- if (!substances.isEmpty()) {
- System.out.printf("Substances: %s\n", String.join(", ", substances.stream().map(String::valueOf).collect(Collectors.toList())));
- }
- if (!challenges.isEmpty()) {
- System.out.printf("Challenges: %s\n", String.join(", ", challenges));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment