From 9d16f1b6b25c82c0f42a67a6b1765494f2955a3e Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sat, 5 Jul 2025 19:03:18 +0900 Subject: [PATCH] 20250705 baekjoon --- code_study/Baekjoon/python/4949.py | 23 +++++++++++++++++++++++ code_study/Baekjoon/ts/9012.ts | 24 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 code_study/Baekjoon/python/4949.py create mode 100644 code_study/Baekjoon/ts/9012.ts diff --git a/code_study/Baekjoon/python/4949.py b/code_study/Baekjoon/python/4949.py new file mode 100644 index 0000000..d927498 --- /dev/null +++ b/code_study/Baekjoon/python/4949.py @@ -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") \ No newline at end of file diff --git a/code_study/Baekjoon/ts/9012.ts b/code_study/Baekjoon/ts/9012.ts new file mode 100644 index 0000000..796d5f7 --- /dev/null +++ b/code_study/Baekjoon/ts/9012.ts @@ -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"); +} \ No newline at end of file