Untitled
unknown
plain_text
a year ago
747 B
9
Indexable
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Stack<Integer> stack = new Stack<Integer>();
while (true) {
String line = sc.nextLine();
if (line.equals("#")) break;
if (line.contains("PUSH")) {
int number = Integer.parseInt(line.split(" ")[1]);
stack.push(number);
} else if (line.contains("POP")) {
if (!stack.isEmpty()) {
System.out.println(stack.pop());
} else {
System.out.println("NULL");
}
}
}
}
}Editor is loading...
Leave a Comment