Home 백준 - 4949 균형잡힌 세상
Post
Cancel

백준 - 4949 균형잡힌 세상

문제

4949 균형잡힌 세상

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
26
27
28
29
30
import java.util.*

fun main() {
    q4949()
}

fun q4949() = with(Scanner(System.`in`)) {
    val inputList = kotlin.collections.ArrayList<String>()
    while (true) {
        val input = nextLine()
        if(input == ".") break
        inputList.add(input)
    }
    inputList.forEach {
        val stack = Stack<Char>()
        var isVps = true
        for(ch in it) when(ch) {
            '(', '[' -> stack.push(ch)
            ')' -> if(stack.isEmpty() || stack.pop() != '(') {
                isVps = false
                break
            }
            ']' -> if(stack.isEmpty() || stack.pop() != '[') {
                isVps = false
                break
            }
        }
        println(if(isVps && stack.empty()) "yes" else "no")
    }
}
This post is licensed under CC BY 4.0 by the author.

백준 - 2908 상수

백준 - 1193 분수찾기 풀이