|
| 1 | +```java |
| 2 | +import java.io.*; |
| 3 | + |
| 4 | +public class BJ_13140_Hello_World { |
| 5 | + |
| 6 | + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 7 | + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 8 | + private static final StringBuilder sb = new StringBuilder(); |
| 9 | + |
| 10 | + private static int N, hello, world; |
| 11 | + private static int[] nums; |
| 12 | + private static boolean[] isSelected; |
| 13 | + |
| 14 | + public static void main(String[] args) throws IOException { |
| 15 | + init(); |
| 16 | + sol(0); |
| 17 | + |
| 18 | + bw.write("No Answer"); |
| 19 | + bw.flush(); |
| 20 | + bw.close(); |
| 21 | + br.close(); |
| 22 | + } |
| 23 | + |
| 24 | + private static void init() throws IOException { |
| 25 | + N = Integer.parseInt(br.readLine()); |
| 26 | + |
| 27 | + nums = new int[7]; |
| 28 | + isSelected = new boolean[10]; |
| 29 | + } |
| 30 | + |
| 31 | + private static void sol(int depth) throws IOException { |
| 32 | + if (depth == 7) { |
| 33 | + calc(); |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + for (int i = 0; i < 10; i++) { |
| 38 | + if (isSelected[i]) continue; |
| 39 | + if ((depth == 0 || depth == 4) && i == 0) continue; |
| 40 | + |
| 41 | + nums[depth] = i; |
| 42 | + isSelected[i] = true; |
| 43 | + sol(depth + 1); |
| 44 | + isSelected[i] = false; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + private static void calc() throws IOException { |
| 49 | + int ans = 0; |
| 50 | + |
| 51 | + hello = nums[0] * 10000 + nums[1] * 1000 + nums[2] * 110 + nums[3]; |
| 52 | + world = nums[4] * 10000 + nums[3] * 1000 + nums[5] * 100 + nums[2] * 10 + nums[6]; |
| 53 | + |
| 54 | + ans = hello + world; |
| 55 | + |
| 56 | + if (ans == N) { |
| 57 | + print(); |
| 58 | + System.exit(0); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + private static void print() throws IOException { |
| 63 | + sb.append(" ").append(hello).append("\n"); |
| 64 | + sb.append("+ ").append(world).append("\n"); |
| 65 | + sb.append("-------\n"); |
| 66 | + sb.append(N / 100000 == 0 ? " " : " ").append(N); |
| 67 | + bw.write(sb.toString()); |
| 68 | + bw.flush(); |
| 69 | + bw.close(); |
| 70 | + br.close(); |
| 71 | + } |
| 72 | + |
| 73 | +} |
| 74 | +``` |
0 commit comments