Home 백준 - 9012 괄호
Post
Cancel

백준 - 9012 괄호

문제

9012 괄호

screencapture

kotlin code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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")
    }
}
This post is licensed under CC BY 4.0 by the author.

백준 - 1157 단어 공부

백준 - 2292 벌집 풀이