균형잡힌 세상 4949
균형잡힌 세상 4949
https://www.acmicpc.net/problem/4949
```python
while True:
input_string=input()
if input_string==".":
break
stack=[]
for idx,character in enumerate(input_string):
if idx==len(input_string)-1:
if len(stack)>0:
print("no")
else:
print("yes")
break
if character in "[]()":
stack.append(character)
if stack[-2:]==["[","]"] or stack[-2:]==["(",")"]:
stack.pop()
stack.pop()
```
## js로도 풀었다.
```javascript
let data = require("fs")
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "./input.txt")
.toString()
.trim()
.split("\n");
for (let j = 0; j < data.length - 1; j++) {
let input_string = data[j];
if (input_string === ".") {
break;
}
stack = [];
for (let i = 0; i < input_string.length; i++) {
if (i === input_string.length - 1) {
if (stack.length > 0) {
console.log("no");
} else {
console.log("yes");
}
break;
}
if (
input_string[i] === "[" ||
input_string[i] === "]" ||
input_string[i] === "(" ||
input_string[i] === ")"
) {
stack.push(input_string[i]);
if (
(stack[stack.length - 2] === "[" && stack[stack.length - 1] === "]") ||
(stack[stack.length - 2] === "(" && stack[stack.length - 1] === ")")
) {
stack.pop();
stack.pop();
}
}
}
}
```
댓글
댓글 쓰기