문제 : www.acmicpc.net/problem/10828
10828번: 스택
첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지
www.acmicpc.net
fun main() = with(System.`in`.bufferedReader()){ val stack = arrayListOf<Int>() val n = readLine().toInt() for(i in 0 until n){ val tmp = readLine().split(" ") when(tmp[0]){ "push" -> { stack.add(tmp[1].toInt()) } "pop" ->{ if (stack.isNotEmpty()) println(stack.removeAt(stack.size - 1)) else println("-1") } "size" ->{ println(stack.size) } "empty" ->{ if (stack.isEmpty()) println("1") else println("0") } "top" -> { if (stack.isNotEmpty()) println(stack[stack.size - 1]) else println("-1") } } } }