Third question
Three goats to offer Rui
Observe the following addition calculation:
Among them, the same Chinese characters represent the same numbers, and the different Chinese characters represent different numbers.
Please fill in the 4-digit number (the answer is the only) represented by "San Yang Rui", do not fill in any superfluous content.
The answer to this topic can use brute force model, that is, choose 8 numbers from the 0~9, make a full arrangement, and then see if the situation matches
But I met a problem here is the brute force model error, how to say, need to choose 8 numbers I ranked 10, and then the results are wrong
Then I thought I was right after all, the answer is only: 1085 flattered
ImportJava.util.Stack;//think about the whole arrangement then select the first eight data to test the data arrangement//If the data review arrangement rules are output//but I'm wrong about this place, with 10 of them all lined up.//then select the first eight of them as data Public classtest3a {Private Static intCount = 0; Private Static intsum = 0; Public Static voidMain (string[] args) {Stack<Integer> stack =NewStack<integer>(); for(inti = 0; I <= 9; i++) {Stack.push (i); Fun (stack); Stack.pop (); } System.out.println (count); SYSTEM.OUT.PRINTLN (sum); } Private Static voidFun (stack<integer>stack) { for(intj = 0; J <= 9; J + +) { if(stack.size () = = 10) { intA = Stack.get (0); intb = Stack.get (1); intc = Stack.get (2); intD = Stack.get (3); intE = Stack.get (4); intf = Stack.get (5); intg = Stack.get (6); intH = stack.get (7); if(check (a, B, C, D, E, F, G, h)) {++count; System.out.printf ("%d%d%d%d%d%d%d%d", A, B, C, D, E, F, G, h); System.out.println (); } return; } if(!Stack.contains (j)) {Stack.push (j); Fun (stack); Stack.pop (); } } } Private Static BooleanCheckint.. args) { intABCD = args[0] * + args[1] * + args[2] * + args[3]; intEFGB = args[4] * + args[5] * + args[6] * + args[1]; intEFCBH = args[4] * 10000 + args[5] * + args[2] * + args[1] * + args[7]; if(ABCD + EFGB = = EFCBH && args[4]! = 0) { return true; } return false; }}
Sixth session of the Blue Bridge Cup Java B group third question