-
Notifications
You must be signed in to change notification settings - Fork 0
/
성냥개비.java
38 lines (29 loc) · 1.38 KB
/
성냥개비.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] matchsticks = {6, 2, 5, 5, 4, 5, 6, 4, 7, 6};
int symbolMatches = 4;
for (int a = 0; a <= 9; a++) {
for (int b = 0; b <= 9; b++) {
for (int c = 0; c <= 9; c++) {
for (int d = 0; d <= 9; d++) {
int sum = (a * 10 + b) + (c * 10 + d);
if (sum >= 100) continue;
int totalMatches = matchsticks[a] + matchsticks[b] +
matchsticks[c] + matchsticks[d] +
matchsticks[sum/10] + matchsticks[sum%10] +
symbolMatches;
if (totalMatches == N) {
System.out.printf("%d%d+%d%d=%d%d\n", a, b, c, d, sum/10, sum%10);
return;
}
}
}
}
}
System.out.println("impossible");
}
}