From 0b00e91f38912aea1c77744d50ca440bcc8decdb Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Mon, 13 Oct 2025 22:42:42 +0900 Subject: [PATCH] =?UTF-8?q?[20251013]=20BOJ=20/=20G5=20/=20=EA=B4=84?= =?UTF-8?q?=ED=98=B8=EC=9D=98=20=EA=B0=92=20/=20=EA=B9=80=EB=AF=BC?= =?UTF-8?q?=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\230\270\354\235\230 \352\260\222.md" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "zinnnn37/202510/13 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" diff --git "a/zinnnn37/202510/13 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" "b/zinnnn37/202510/13 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" new file mode 100644 index 00000000..686ee0ab --- /dev/null +++ "b/zinnnn37/202510/13 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" @@ -0,0 +1,71 @@ +```java +import java.io.*; +import java.util.Stack; + +public class BJ_2504_괄호의_값 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + private static int ans, tmp, len; + private static String str; + + private static Stack stack; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + str = br.readLine(); + len = str.length(); + ans = 0; + tmp = 1; + stack = new Stack<>(); + } + + private static void sol() throws IOException { + for (int i = 0; i < len; i++) { + char c = str.charAt(i); + + if (c == '(') { + tmp *= 2; + stack.push(c); + } else if (c == '[') { + tmp *= 3; + stack.push(c); + } else { + if (stack.isEmpty() || c == ')' && stack.peek() != '(' || c == ']' && stack.peek() != '[') { + ans = 0; + break; + } + + if (c == ')') { + if (str.charAt(i - 1) == '(') { + ans += tmp; + } + tmp /= 2; + stack.pop(); + } else if (c == ']') { + if (str.charAt(i - 1) == '[') { + ans += tmp; + } + tmp /= 3; + stack.pop(); + } + } + } + + if (!stack.isEmpty()) { + ans = 0; + } + + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file