20250705 baekjoon
This commit is contained in:
parent
8f8e0ca19a
commit
9d16f1b6b2
23
code_study/Baekjoon/python/4949.py
Normal file
23
code_study/Baekjoon/python/4949.py
Normal file
@ -0,0 +1,23 @@
|
||||
while True:
|
||||
stack = []
|
||||
line = input()
|
||||
if line=="." :
|
||||
break
|
||||
|
||||
isBalance = True
|
||||
for c in line:
|
||||
if c == "(":
|
||||
stack.append(c)
|
||||
elif c== ")":
|
||||
if not stack or stack[-1] != "(":
|
||||
isBalance = False
|
||||
break
|
||||
stack.pop()
|
||||
elif c == "[":
|
||||
stack.append(c)
|
||||
elif c== "]":
|
||||
if not stack or stack[-1] != "[":
|
||||
isBalance = False
|
||||
break
|
||||
stack.pop()
|
||||
print("yes" if isBalance and not stack else "no")
|
||||
24
code_study/Baekjoon/ts/9012.ts
Normal file
24
code_study/Baekjoon/ts/9012.ts
Normal file
@ -0,0 +1,24 @@
|
||||
export {};
|
||||
const lines = require("fs").readFileSync(0,"utf8").toString().trim().split('\n');
|
||||
|
||||
const isEmpty = (arr:string[]) => arr.length === 0;
|
||||
const lastValue = (arr:string[]) => arr[arr.length-1];
|
||||
const n = Number(lines[0]);
|
||||
for(let i=1; i<=n; i++){
|
||||
let stack:string[] = [];
|
||||
let flag:boolean = true;
|
||||
let line = lines[i];
|
||||
for(let ch of line) {
|
||||
if(ch === "(") {
|
||||
stack.push(ch);
|
||||
}
|
||||
else if(ch === ")") {
|
||||
if(isEmpty(stack) || lastValue(stack) !== "(") {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
console.log((isEmpty(stack) && flag) ? "YES" : "NO");
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user