From cffc4a75f71733cec1b5cc57cdf4c8cf8163bf1c Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Thu, 13 Feb 2025 16:34:06 +0900 Subject: [PATCH] =?UTF-8?q?[20250213]=20BOJ=20/=20=EA=B3=A8=EB=93=9C4=20/?= =?UTF-8?q?=20=EC=97=B0=EC=82=B0=EC=9E=90=20=EB=81=BC=EC=9B=8C=EB=84=A3?= =?UTF-8?q?=EA=B8=B0=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\233\214\353\204\243\352\270\260(3).md" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "lkhyun/202502/13 BOJ \352\263\250\353\223\2344 \354\227\260\354\202\260\354\236\220 \353\201\274\354\233\214\353\204\243\352\270\260(3).md" diff --git "a/lkhyun/202502/13 BOJ \352\263\250\353\223\2344 \354\227\260\354\202\260\354\236\220 \353\201\274\354\233\214\353\204\243\352\270\260(3).md" "b/lkhyun/202502/13 BOJ \352\263\250\353\223\2344 \354\227\260\354\202\260\354\236\220 \353\201\274\354\233\214\353\204\243\352\270\260(3).md" new file mode 100644 index 00000000..7c202738 --- /dev/null +++ "b/lkhyun/202502/13 BOJ \352\263\250\353\223\2344 \354\227\260\354\202\260\354\236\220 \353\201\274\354\233\214\353\204\243\352\270\260(3).md" @@ -0,0 +1,88 @@ +```java +import java.util.*; +import java.io.*; +public class Main{ + static int N; + static int[] numbers; + static int[] operator = new int[4]; + static int max = Integer.MIN_VALUE; + static int min = Integer.MAX_VALUE; + static ArrayDeque operation = new ArrayDeque<>(); + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + N = Integer.parseInt(br.readLine()); + numbers = new int[N]; + StringTokenizer st = new StringTokenizer(br.readLine()); + for(int i=0;i operandStk = new ArrayDeque<>(); + ArrayDeque operatorStk = new ArrayDeque<>(); + ArrayDeque provider = operation.clone(); + while(!provider.isEmpty()){ + if(!operandStk.isEmpty() && !operatorStk.isEmpty() && operatorStk.getLast()>=2){ + int operand = operandStk.pollLast(); + int opcode = operatorStk.pollLast(); + int result = calculate(operand, provider.pollFirst(), opcode); + operandStk.addLast(result); + operatorStk.addLast(provider.pollFirst()); + }else{ + operandStk.addLast(provider.pollFirst()); + operatorStk.addLast(provider.pollFirst()); + } + } + if(!operatorStk.isEmpty() && operatorStk.getLast()>=2){ + lastElement = calculate(operandStk.pollLast(), lastElement, operatorStk.pollLast()); + } + operandStk.addLast(lastElement); + total = operandStk.pollFirst(); + while(!operandStk.isEmpty() && !operatorStk.isEmpty()){ + total = calculate(total, operandStk.pollFirst(), operatorStk.pollFirst()); + } + max = Math.max(max,total); + min = Math.min(min,total); + return; + } + + for(int i=0;i<4;i++){ + if(operator[i] > 0){ + operation.addLast(numbers[depth]); + operation.addLast(i); + operator[i]--; + findMaxMin(depth+1); + operator[i]++; + operation.pollLast(); + operation.pollLast(); + } + } + } + public static int calculate(int x, int y, int op){// 0:+ 1:- 2:x 3:/ + if(op==0){ + return x+y; + }else if(op==1){ + return x-y; + }else if(op==2){ + return x*y; + }else if(op==3){ + return x/y; + } + return 0; + } +} +```