https://www.acmicpc.net/problem/10828
import java.util.*;
class Stack {
int size;
int[] stack;
public Stack(int num){
stack = new int[num];
size=0;
}
public void push(int num) {
stack[size] = num;
size++;
}
public int pop() {
if(size == 0) return -1;
else {
int ans = stack[size - 1];
stack[size - 1] = 0;
size--;
return ans;
}
}
public int size() {
return size;
}
public int empty() {
if(size == 0) return 1;
else return 0;
}
public int top() {
if(size == 0) return -1;
else return stack[size - 1];
}
}
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int n=s.nextInt();
Stack t=new Stack(n);
for(int i=0;i<n;i++) {
String st = s.next();
switch (st) {
case "push":
t.push(s.nextInt());
break;
case "pop":
sb.append(t.pop()).append('\n');
break;
case "size":
sb.append(t.size()).append('\n');
break;
case "empty":
sb.append(t.empty()).append('\n');
break;
case "top":
sb.append(t.top()).append('\n');
break;
}
}
System.out.println(sb);
}
}