https://www.acmicpc.net/problem/10828
using System;
using System.Text;
class Stack {
int si;
int[] stack;
public Stack(int num){
stack = new int[num];
si=0;
}
public void push(int num) {
stack[si] = num;
si++;
}
public int pop() {
if(si == 0) return -1;
else {
int ans = stack[si - 1];
stack[si - 1] = 0;
si--;
return ans;
}
}
public int size() {
return si;
}
public int empty() {
if(si == 0) return 1;
else return 0;
}
public int top() {
if(si == 0) return -1;
else return stack[si - 1];
}
}
class Program
{
static void Main() {
string st=Console.ReadLine();
StringBuilder sb = new StringBuilder();
int n=int.Parse(st);
Stack t=new Stack(n);
for(int i=0;i<n;i++){
string[] st1=Console.ReadLine().Split();
switch (st1[0]) {
case "push":
t.push(int.Parse(st1[1]));
break;
case "pop":
sb.Append(t.pop()+"\n");
break;
case "size":
sb.Append(t.size()+"\n");
break;
case "empty":
sb.Append(t.empty()+"\n");
break;
case "top":
sb.Append(t.top()+"\n");
break;
}
}
Console.WriteLine(sb.ToString());
}
}