Advertisement
desislava_topuzakova

Untitled

Jun 20th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. import java.io.Console;
  2. import java.util.*;
  3. import java.util.stream.Collectors;
  4.  
  5. public class Ex2 {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. Queue<Integer> tools = new LinkedList<>(Arrays.stream(scanner.nextLine().split(" ", -1))
  11. .mapToInt(Integer::parseInt)
  12. .boxed()
  13. .collect(Collectors.toList()));
  14.  
  15. Stack<Integer> substances = new Stack<>();
  16. Arrays.stream(scanner.nextLine().split(" ", -1))
  17. .mapToInt(Integer::parseInt)
  18. .forEach(substances::push);
  19.  
  20. List<Integer> challenges = new ArrayList<>(Arrays.stream(scanner.nextLine().split(" ", -1))
  21. .mapToInt(Integer::parseInt)
  22. .boxed()
  23. .collect(Collectors.toList()));
  24.  
  25. while (true) {
  26. int tool = tools.peek();
  27. int substance = substances.peek();
  28.  
  29. if (challenges.contains(tool * substance)) {
  30. challenges.remove(Integer.valueOf(tool * substance));
  31. tools.poll();
  32. substances.pop();
  33.  
  34. if (challenges.isEmpty()) {
  35. System.out.println("Harry found an ostracon, which is dated to the 6th century BCE.");
  36. break;
  37. }
  38.  
  39. } else {
  40. tools.offer(tools.poll() + 1);
  41. substances.push(substances.pop() - 1);
  42.  
  43. if (substances.peek() == 0) {
  44. substances.pop();
  45. }
  46.  
  47. if (substances.isEmpty()) {
  48. System.out.println("Harry is lost in the temple. Oblivion awaits him.");
  49. break;
  50. }
  51. }
  52. }
  53.  
  54. if (!tools.isEmpty()) {
  55. System.out.println("Tools: " + tools.stream().map(Object::toString).collect(Collectors.joining(", ")));
  56. }
  57. if (!substances.isEmpty()) {
  58. System.out.println("Substances: " + substances.stream().map(Object::toString).collect(Collectors.joining(", ")));
  59. }
  60. if (!challenges.isEmpty()) {
  61. System.out.println("Challenges: " + challenges.stream().map(Object::toString).collect(Collectors.joining(", ")));
  62. }
  63.  
  64. scanner.close();
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement