Skip to content

Commit 7adcbbb

Browse files
authored
[20251108] BOJ / G5 / Hello World! / 이강현
1 parent 37e27b5 commit 7adcbbb

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringBuilder sb = new StringBuilder();
9+
static StringTokenizer st;
10+
static int N;
11+
static int[] helowrd = new int[7];
12+
static boolean[] numbers = new boolean[10];
13+
static boolean finished;
14+
static int A,B;
15+
public static void main(String[] args) throws Exception {
16+
N = Integer.parseInt(br.readLine());
17+
backtracking(0);
18+
if(A == 0){
19+
bw.write("No Answer");
20+
bw.close();
21+
return;
22+
}
23+
bw.write(String.format("%7d\n", A));
24+
bw.write(String.format("+ %5d\n", B));
25+
bw.write("-------\n");
26+
bw.write(String.format("%7d", N));
27+
bw.close();
28+
}
29+
public static void backtracking(int depth){
30+
if(finished) return;
31+
if(depth == 7){
32+
int a = 10000*helowrd[0] + 1000*helowrd[1] + 100*helowrd[2] + 10*helowrd[2] + helowrd[3];
33+
int b = 10000*helowrd[4] + 1000*helowrd[3] + 100*helowrd[5] + 10*helowrd[2] + helowrd[6];
34+
if((a+b) == N){
35+
finished = true;
36+
A = a;
37+
B = b;
38+
}
39+
return;
40+
}
41+
42+
for(int i = 0; i<10; i++){
43+
if(depth==0 && i==0) continue;
44+
if(depth==4 && i==0) continue;
45+
if(!numbers[i]){
46+
helowrd[depth] = i;
47+
numbers[i] = true;
48+
backtracking(depth+1);
49+
numbers[i] = false;
50+
}
51+
}
52+
}
53+
}
54+
```

0 commit comments

Comments
 (0)