package org.javatests; import java.util.Stack; public class Ex1 { public Boolean transactions(String input) { String[] arr = input.split(" "); final var stack = new Stack(); for (String s : arr) { String op = s.replace("OP_", ""); if (op.chars().allMatch(Character::isDigit)) { Integer number = Integer.parseInt(op); stack.push(number); } else if (!stack.isEmpty()) { if (op.equals("EQUAL")) { if (stack.pop().equals(stack.pop())) stack.push(1); else stack.push(0); } else if (op.equals("ADD")) { Integer res = stack.pop() + stack.pop(); stack.push(res); } else if (op.equals("SUB")) { Integer top = stack.pop(); Integer second = stack.pop(); stack.push(second - top); } else if (op.equals("VERIFY")) { if (stack.peek().equals(0)) return false; else stack.pop(); } } } return !stack.isEmpty() && stack.pop() != 0; } }