프로그래머스/코딩연습1
[백준] 스택 (10828)(Kotlin)
유줘니
2020. 1. 20. 14:26
원본 문제 : https://www.acmicpc.net/problem/10828
문제 참고 : https://bcp0109.tistory.com/83
<첫번째>
import java.io.*
import java.util.*
fun main() = with(BufferedReader(InputStreamReader(System.`in`))){
val br = BufferedReader(InputStreamReader(System.`in`))
val stack = Stack<Int>()
val bw = BufferedWriter(OutputStreamWriter(System.out))
repeat(readLine().toInt()) {
val input = readLine().split(" ")
when(input[0]) {
"push" -> stack.push(input[1].toInt())
"pop" -> bw.write("${if (stack.empty()) - 1 else stack.pop() }\n")
"size" -> bw.write("${stack.size}\n")
"empty" -> bw.write("${if (stack.empty()) 1 else 0}\n")
"top" -> bw.write("${if (stack.empty()) -1 else stack.peek() }\n")
}
}
bw.flush()
}