File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments