문제
4949 균형잡힌 세상
답
kotlin code
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")
}
}