원본 문제 : 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()
}
'프로그래머스 > 코딩연습1' 카테고리의 다른 글
[프로그래머스] 모의고사 (42840)(Kotlin) (0) | 2020.01.20 |
---|---|
[프로그래머스] 쇠막대기(42585)(Kotlin) (0) | 2020.01.16 |
[프로그래머스] 탑(42588)(Kotlin) (0) | 2020.01.16 |
[프로그래머스] 체육복(42862)(Kotlin) (0) | 2020.01.16 |
[프로그래머스] 기능개발(42586)(Kotlin) (0) | 2020.01.14 |
댓글