Problem-Solving/BOJ
[BOJ/백준][Silver4] 10845 : 큐 (Kotlin)
has2
2021. 5. 18. 22:19
[20210510] 큐
[BOJ/백준][Silver4] 10845 : 큐 (Kotlin)
https://www.acmicpc.net/problem/10845
10845번: 큐
첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지
www.acmicpc.net
[난이도] Silver4
[유형] 큐
[풀이]
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*
fun main() = with(BufferedReader(InputStreamReader(System.`in`))){
var n = readLine().toInt()
var q:Queue<Int> = LinkedList<Int>()
while(n-->0){
var ip=readLine().split(' ')
when(ip[0]){
"push"->q.add(ip[1].toInt())
"pop"-> println(if(q.isEmpty()) -1 else q.poll())
"empty"->println(if(q.isEmpty()) 1 else 0)
"front"->println(if(q.isEmpty()) -1 else q.peek())
"back"->println(if(q.isEmpty()) -1 else q.last())
else->println(q.size)
}
}
}
https://github.com/has2/Problem-Solving/blob/master/boj-solved.ac/Silver4/10845.cpp