From 02799a7880b8761f906102e84266bcc7c4927514 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 27 Sep 2025 10:49:25 +0900 Subject: [PATCH] =?UTF-8?q?[20250927]=20BOJ=20/=20G3=20/=20=EA=B4=84?= =?UTF-8?q?=ED=98=B8=20=EC=B6=94=EA=B0=80=ED=95=98=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\352\260\200\355\225\230\352\270\260.md" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "lkhyun/202509/27 BOJ G3 \352\264\204\355\230\270 \354\266\224\352\260\200\355\225\230\352\270\260.md" diff --git "a/lkhyun/202509/27 BOJ G3 \352\264\204\355\230\270 \354\266\224\352\260\200\355\225\230\352\270\260.md" "b/lkhyun/202509/27 BOJ G3 \352\264\204\355\230\270 \354\266\224\352\260\200\355\225\230\352\270\260.md" new file mode 100644 index 00000000..0dd1d175 --- /dev/null +++ "b/lkhyun/202509/27 BOJ G3 \352\264\204\355\230\270 \354\266\224\352\260\200\355\225\230\352\270\260.md" @@ -0,0 +1,56 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static StringBuilder sb = new StringBuilder(); + static int N; + static String line; + static int max = Integer.MIN_VALUE; + + public static void main(String[] args) throws Exception { + N = Integer.parseInt(br.readLine()); + line = br.readLine(); + + dfs(0, Integer.parseInt(String.valueOf(line.charAt(0)))); + bw.write(max+""); + bw.close(); + } + static void dfs(int idx, int cur) { + + if (idx >= N - 1) { + max = Math.max(max, cur); + return; + } + + char operator = line.charAt(idx + 1); + int nextNum = Integer.parseInt(String.valueOf(line.charAt(idx + 2))); + + int noBracket = calculate(cur, operator, nextNum); + dfs(idx + 2, noBracket); + + if (idx + 4 < N) { + char nextOperator = line.charAt(idx + 3); + int nextNextNum = Integer.parseInt(String.valueOf(line.charAt(idx + 4))); + + int bracketResult = calculate(nextNum, nextOperator, nextNextNum); + int Bracket = calculate(cur, operator, bracketResult); + dfs(idx + 4, Bracket); + } + } + static int calculate(int a, char op, int b) { + if(op == '+'){ + return a+b; + }else if(op == '-'){ + return a-b; + }else if(op == '*'){ + return a*b; + }else{ + return 0; + } + } +} +```