From b252698e7dec1281b919db28dc17087eb897bdb8 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sun, 7 Sep 2025 23:58:47 +0900 Subject: [PATCH] =?UTF-8?q?[20250907]=20BOJ=20/=20G4=20/=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=88=98=20/=20=EC=9D=B4=EC=A2=85?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...265 \354\227\206\353\212\224 \354\210\230" | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 "0224LJH/202509/07 BOJ \354\244\221\353\263\265 \354\227\206\353\212\224 \354\210\230" diff --git "a/0224LJH/202509/07 BOJ \354\244\221\353\263\265 \354\227\206\353\212\224 \354\210\230" "b/0224LJH/202509/07 BOJ \354\244\221\353\263\265 \354\227\206\353\212\224 \354\210\230" new file mode 100644 index 00000000..a044da82 --- /dev/null +++ "b/0224LJH/202509/07 BOJ \354\244\221\353\263\265 \354\227\206\353\212\224 \354\210\230" @@ -0,0 +1,102 @@ +``` +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + + static int[] max = {0,9,98,987,9876,98765,987654,9876543,98765432,987654321}; + static int[] min = {0,1,12,123,1234,12345,123456,1234567,12345678,123456789}; + static int ans,target; + static int[] num; + + + static boolean[] used = new boolean[10]; + + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(System.in); + + while(sc.hasNext()) { + target = sc.nextInt(); + ans = -1; + process(); + print(); + } + sc.close(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + ans = -1; + target = Integer.parseInt(br.readLine()); + + } + + public static void process() throws IOException { + if (target >= max[9]) { + ans = 0; + return; + } + + + int size = 0; + + for (int i = 8; i >= 0; i--) { + if (target / Math.pow(10, i) >= 1) { + size = i+1; + break; + } + } + + if (target >= max[size]) { + ans = min[size+1]; + return; + } + + num = new int[size]; + + + recur( 0, size); + + } + + private static void recur(int cur, int goal) { + if (ans != -1) return; + + if (cur == goal) { + int res = 0; + for (int i = 0; i < goal; i++) { + res*=10; + res+=num[i]; + } + ans = res; + return; + } + + int original = (target / (int)Math.pow(10, goal - cur - 1)) % 10; + int nNum = -1; + + for (int i = 1; i <= 9; i++) { + if (!used[i] && i >= original) { + used[i] = true; + num[cur] = i; + recur(cur+1, goal); + used[i] = false; + } + } + + + } + + + + + + + + public static void print() { + System.out.println(ans); + } +``` +}