Sherlock Holmes went on an adventure in a castle and saw a strange formula on the door: ABCDE *? = Edcba

Source: Internet
Author: User
/** The castle formula Sherlock Holmes went to explore a castle and saw a strange formula written on the door: ABCDE *? = Edcba he said to Watson: "ABCDE should represent different numbers. A question mark also represents a number !" WATSON: "I guess so !" As a result, the two were silenced for a long time and still did not come up with the appropriate results. Please take advantage of your computer to find the answer to the attack. Write the number represented by ABCDE. The answer is written in dig into. txt. Do not write it here! */Public class tdemo02_two {public static void main (string [] ARGs) {for (INT I = 10000; I <100000; I ++) {int A = I/10000; int B = I % 10000/1000; int c = I % 10000% 1000/100; int d = I % 10000% 1000% 100/10; int e = I % 10; if (A = B | A = c | A = d | A = E | B = c | B = d | B = = E | C = d | C = E | D = E) {continue;} int y = E * 10000 + D * 1000 + C * 100 + B * 10 + A; If (Y % I = 0) {system. out. println (I + "*" + Y/I + "=" + Y );}}}}

Running result:

21978*4=87912

Method 2:

/** The castle formula Sherlock Holmes went to explore a castle and saw a strange formula written on the door: ABCDE *? = Edcba he said to Watson: "ABCDE should represent different numbers. A question mark also represents a number !" WATSON: "I guess so !" As a result, the two were silenced for a long time and still did not come up with the appropriate results. Please take advantage of your computer to find the answer to the attack. Write the number represented by ABCDE. The answer is written in dig into. txt. Do not write it here! */Public class demo02 {// check whether all 111111... public static Boolean check (INT [] B) {Boolean flag = true; For (INT I = 0; I <B. length; I ++) {If (B [I] = 0) {flag = false; break;} return flag ;} // check whether it is a five-digit public static Boolean checkfive (INT [] B) {Boolean flag = false; int COUNT = 0; For (INT I = 0; I <B. length; I ++) {If (B [I] = 1) {count ++ ;}} if (COUNT = 5) Flag = true; return flag ;} // obtain a five-digit public static string values (INT [] B) {Str Ingbuffer sb = new stringbuffer (); For (INT I = 0; I <B. length; I ++) {If (B [I]! = 0) {sb. append (I) ;}return sb. tostring () ;}// reverse npublic static int reverse (int n) {stringbuffer sb = new stringbuffer (); sb. append (n); sb. reverse (); Return integer. parseint (sb. tostring ();} // carry to get the next digit public static void modify (INT [] B) {B [B. length-1] ++; For (INT I = B. length-1; I> 0; I --) {If (B [I]> 1) {B [I] = 0; B [I-1] ++ ;}}} public static void calc (string s) {int n = integer. parseint (s); // obtain a five-digit int r = reverse (N ); // Reverse NIF (R % N = 0) // obtain the result N *? = Rsystem. out. println (n + "*" + (R/n) + "=" + r);} public static void Allsort (char [] C, int start, int end) {char temp = 0; If (START = END) {string S = new string (c); If (S. charat (0)-'0 ')! = 0) {calc (s); // calculation result} else {for (INT I = start; I <= end; I ++) {temp = C [start]; C [start] = C [I]; C [I] = temp; Allsort (C, start + 1, end ); temp = C [start]; C [start] = C [I]; C [I] = temp ;}} public static void F (INT [] B) {for (;) {If (check (B) break; // check whether all 111111... modify (B); // carry, test the next number if (! Checkfive (B) continue; // check whether it is a five-digit string S = values (B); // obtain a five-digit char [] C = S. tochararray (); Allsort (C, 0, C. length-1); // arrange one of the five digits in full and calculate the result} public static void main (string [] ARGs) {int [] B = new int [10]; F (B );}}

Running result:

21978*4=87912

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.