[C/C ++] Sherlock Holmes ABCDE *? = Edcba

Source: Internet
Author: User
/* Sherlock Holmes went on an adventure in a castle and saw a strange formula 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. */# Include <iostream> using namespace STD; void main () {int K, T1, T; // What is T1? , K is ABCDE, t is edcba // edcba is bigger than ABCDE, and at least 2 times // the minimum value of ABCDE is 10234 for (k = 10234; k <50000; k ++) {// K = 10234 bool flag [10] = {0}; t = K; T1 = 0; while (t) {If (flag [T % 10]) // there are 10 false values in the flag, T % 10, remainder, flag [T % 10] Break; flag [T % 10] = true; // if the previous step is false, if there is no break, set flag [T % 10] to true to exclude the occurrence of identical numbers T1 = T1 * 10 + T % 10; // T1 stands for edcba t/= 10;} // traverses all numbers that do not have the same number if (t = 0 & T1 % K = 0) {// T = 0, because ABCDE In the subscript of flag , So t = 0; while T1 % K = 0, that is, T1/k = ?,? Is an integer cout <k <"*" <t1/k <"=" <t1 <Endl ;}}}

 

Related Article

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.