문제 : www.acmicpc.net/problem/1874
1874번: 스택 수열
1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다.
www.acmicpc.net
fun main() = with(System.`in`.bufferedReader()){ val n = readLine().toInt() val stack = arrayListOf<Int>() val str = arrayListOf<String>() var count = 0 var tmp = 0 for(i in 0 until n){ tmp = readLine().toInt() if(count < tmp) { for (j in count+1 .. tmp) { stack.add(j) str.add("+") } count = tmp } else if(stack[stack.size-1] != tmp){ println("NO") return } stack.removeAt(stack.size-1) str.add("-") } str.forEach { println(it) } }