borovaneca

TempleOfDoom

Jun 17th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayDeque;
  5. import java.util.Arrays;
  6. import java.util.List;
  7. import java.util.stream.Collectors;
  8.  
  9. public class TempleOfDoom {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.  
  14.         ArrayDeque<Integer> tools = new ArrayDeque<>(Arrays.stream(scanner.readLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList()));
  15.         ArrayDeque<Integer> substances = new ArrayDeque<>();
  16.         Arrays.stream(scanner.readLine().split("\\s+")).map(Integer::parseInt).forEach(substances::push);
  17.         List<String> challenges = Arrays.stream(scanner.readLine().split("\\s+")).collect(Collectors.toList());
  18.  
  19.         while (!tools.isEmpty() && !substances.isEmpty()) {
  20.  
  21.             int currentTool = tools.poll();
  22.             int currentSubstance = substances.pop();
  23.             int sum = currentSubstance * currentTool;
  24.  
  25.             if (challenges.contains(String.valueOf(sum))) {
  26.                 challenges.remove(String.valueOf(sum));
  27.  
  28.             } else {
  29.                 tools.offer(currentTool + 1);
  30.                 currentSubstance--;
  31.                 if (currentSubstance > 0) {
  32.                     substances.push(currentSubstance);
  33.                 }
  34.             }
  35.         }
  36.  
  37.         if (!challenges.isEmpty() && tools.isEmpty() || !challenges.isEmpty() && substances.isEmpty()) {
  38.             System.out.println("Harry is lost in the temple. Oblivion awaits him.");
  39.         } else {
  40.             System.out.println("Harry found an ostracon, which is dated to the 6th century BCE.");
  41.         }
  42.  
  43.         if (!tools.isEmpty()) {
  44.             System.out.printf("Tools: %s\n", String.join(", ", tools.stream().map(String::valueOf).collect(Collectors.toList())));
  45.         }
  46.         if (!substances.isEmpty()) {
  47.             System.out.printf("Substances: %s\n", String.join(", ", substances.stream().map(String::valueOf).collect(Collectors.toList())));
  48.         }
  49.         if (!challenges.isEmpty()) {
  50.             System.out.printf("Challenges: %s\n", String.join(", ", challenges));
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment