From 7adcbbbe37b4da637be2ca3f8d9dbad918fcc1b5 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 8 Nov 2025 19:45:20 +0900 Subject: [PATCH] =?UTF-8?q?[20251108]=20BOJ=20/=20G5=20/=20Hello=20World!?= =?UTF-8?q?=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 --- lkhyun/202511/08 BOJ G5 Hello World!.md | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lkhyun/202511/08 BOJ G5 Hello World!.md diff --git a/lkhyun/202511/08 BOJ G5 Hello World!.md b/lkhyun/202511/08 BOJ G5 Hello World!.md new file mode 100644 index 00000000..c26ba55b --- /dev/null +++ b/lkhyun/202511/08 BOJ G5 Hello World!.md @@ -0,0 +1,54 @@ +```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 StringBuilder sb = new StringBuilder(); + static StringTokenizer st; + static int N; + static int[] helowrd = new int[7]; + static boolean[] numbers = new boolean[10]; + static boolean finished; + static int A,B; + public static void main(String[] args) throws Exception { + N = Integer.parseInt(br.readLine()); + backtracking(0); + if(A == 0){ + bw.write("No Answer"); + bw.close(); + return; + } + bw.write(String.format("%7d\n", A)); + bw.write(String.format("+ %5d\n", B)); + bw.write("-------\n"); + bw.write(String.format("%7d", N)); + bw.close(); + } + public static void backtracking(int depth){ + if(finished) return; + if(depth == 7){ + int a = 10000*helowrd[0] + 1000*helowrd[1] + 100*helowrd[2] + 10*helowrd[2] + helowrd[3]; + int b = 10000*helowrd[4] + 1000*helowrd[3] + 100*helowrd[5] + 10*helowrd[2] + helowrd[6]; + if((a+b) == N){ + finished = true; + A = a; + B = b; + } + return; + } + + for(int i = 0; i<10; i++){ + if(depth==0 && i==0) continue; + if(depth==4 && i==0) continue; + if(!numbers[i]){ + helowrd[depth] = i; + numbers[i] = true; + backtracking(depth+1); + numbers[i] = false; + } + } + } +} +```