From fbb48e25e0c0bac971da87146a5558276ccfed9d Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Mon, 13 Oct 2025 23:43:53 +0900 Subject: [PATCH] =?UTF-8?q?Create=2013=20BOJ=20G5=20=EA=B4=84=ED=98=B8?= =?UTF-8?q?=EC=9D=98=20=EA=B0=92.md?= 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" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "Seol-JY/202510/13 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" diff --git "a/Seol-JY/202510/13 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" "b/Seol-JY/202510/13 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" new file mode 100644 index 00000000..7437abb9 --- /dev/null +++ "b/Seol-JY/202510/13 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" @@ -0,0 +1,58 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String s = br.readLine(); + + System.out.println(solution(s)); + } + + static int solution(String s) { + Deque deque = new ArrayDeque<>(); + int result = 0; + int temp = 1; + + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + + if (c == '(') { + deque.push(c); + temp *= 2; + } + else if (c == '[') { + deque.push(c); + temp *= 3; + } + else if (c == ')') { + if (deque.isEmpty() || deque.peek() != '(') { + return 0; + } + + if (s.charAt(i - 1) == '(') { + result += temp; + } + + deque.pop(); + temp /= 2; + } + else if (c == ']') { + if (deque.isEmpty() || deque.peek() != '[') { + return 0; + } + + if (s.charAt(i - 1) == '[') { + result += temp; + } + + deque.pop(); + temp /= 3; + } + } + + return deque.isEmpty() ? result : 0; + } +} +```