문제
9012 괄호
답
kotlin code
import java.util.*
fun main() {
q9012()
}
fun q9012() = with(Scanner(System.`in`)) {
val inputs = List(nextInt()) {next()}
for(input in inputs) {
var isVps = true
val stack = Stack<Char>()
for (char in input.toCharArray()) when (char) {
'(' -> stack.push(char)
')' -> {
if (stack.isEmpty()) {
isVps = false
break
}
stack.pop()
}
}
if(stack.isNotEmpty()) isVps = false
println(if(isVps) "YES" else "NO")
}
}