Skip to content

Commit 8b7497e

Browse files
authored
Merge pull request #1485 from AlgorithmWithGod/JHLEE325
[20251123] BOJ / G5 / 홀수 홀릭 호석 / 이준희
2 parents 9538909 + 5fb9405 commit 8b7497e

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static int min = Integer.MAX_VALUE;
8+
static int max = Integer.MIN_VALUE;
9+
10+
public static void main(String[] args) throws Exception {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
13+
String N = br.readLine();
14+
dfs(N, 0);
15+
16+
System.out.println(min + " " + max);
17+
}
18+
19+
static void dfs(String num, int totalOdd) {
20+
21+
int curOdd = countOdd(num);
22+
totalOdd += curOdd;
23+
24+
int len = num.length();
25+
26+
if (len == 1) {
27+
min = Math.min(min, totalOdd);
28+
max = Math.max(max, totalOdd);
29+
return;
30+
}
31+
32+
if (len == 2) {
33+
int sum = (num.charAt(0) - '0') + (num.charAt(1) - '0');
34+
dfs(String.valueOf(sum), totalOdd);
35+
return;
36+
}
37+
38+
for (int i = 1; i < len - 1; i++) {
39+
for (int j = i + 1; j < len; j++) {
40+
41+
int a = Integer.parseInt(num.substring(0, i));
42+
int b = Integer.parseInt(num.substring(i, j));
43+
int c = Integer.parseInt(num.substring(j));
44+
45+
int sum = a + b + c;
46+
47+
dfs(String.valueOf(sum), totalOdd);
48+
}
49+
}
50+
}
51+
52+
static int countOdd(String s) {
53+
int cnt = 0;
54+
for (char c : s.toCharArray()) {
55+
if ((c - '0') % 2 == 1) cnt++;
56+
}
57+
return cnt;
58+
}
59+
}
60+
```

0 commit comments

Comments
 (0)