Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int[] stack = new int[1000000];
- int size = 0;
- String command;
- while (true) {
- command = sc.nextLine();
- if (command.contains("push")) {
- stack[size++] = Integer.parseInt(command.substring(5));
- System.out.println("ok");
- }
- if (command.contains("pop")) {
- System.out.println(stack[size - 1]);
- stack[size--] = 0;
- }
- if (command.contains("back")) {
- System.out.println(stack[size - 1]);
- }
- if (command.contains("size")) {
- System.out.println(size);
- }
- if (command.contains("clear")) {
- if (size == 0) {
- System.out.println("ok");
- } else {
- for (int i = 0; i < size; i++) {
- stack[i] = 0;
- }
- size = 0;
- System.out.println("ok");
- }
- }
- if (command.contains("exit")) {
- System.out.println("bye");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment