A boring mathematical problem ABCD * x = fghi (9 1-9 numbers that are not repeated) is implemented in C #

Source: Internet
Author: User

There was a bored person in the group who talked about a math problem.

So I also tried programming.

 

The Code is as follows:

 

Int A = 0, B = 0, c = 0, D = 0, x = 0, F, G, H, I, ABCD, fghi; </P> <p> for (a = 1; A <10; A ++) <br/> {<br/> for (B = 1; B <10; B ++) <br/>{< br/> if (a = B) <br/>{< br/> continue; <br/>}</P> <p> for (C = 1; C <10; C ++) <br/>{< br/> if (a = c | B = C) <br/>{< br/> continue; <br/>}</P> <p> for (D = 1; D <10; D ++) <br/>{< br/> If (A = d | B = d | C = d) <br/>{< br/> continue; <br/>} </P> <p> for (x = 1; x <10; X ++) <br/>{< br/> If (A = x | B = x | D = x | C = x) <br/>{< br/> continue; <br/>}< br/> ABCD = a + B * 10 + C * 100 + D * 1000; <br/> fghi = ABCD * X; </P> <p> // a four-digit method, clever application of the Division and Division <br/> F = fghi/1000; <br/> G = (fghi % 1000)/100; <br/> H = (fghi % 1000) % 100)/10; <br/> I = (fghi % 1000) % 100) % 10; </P> <p> // determines whether the number in the result contains A, B, C, and D and the result does not contain 0. The result is confirmed to be 4 digits.. <Br/> If (fghi. tostring (). contains (. tostring () | fghi. tostring (). contains (B. tostring () | fghi. tostring (). contains (C. tostring () | fghi. tostring (). contains (X. tostring () | fghi. tostring (). contains (D. tostring () | fghi. tostring (). length> 4 | fghi. tostring (). contains ("0") <br/>{< br/> continue; <br/>}</P> <p> else <br/>{< br/> If (F! = G & F! = H & F! = I & G! = H & G! = I & H! = I) <br/>{< br/> response. write (fghi + "" + ABCD + "" + x); <br/> response. write ("<br/> "); </P> <p >}< br/>}</P> <p >}< br/>}

 

The clever use of C # Is that the result is converted to a string. then, the contains (string a) method is applied to check whether the query result contains the four digits in the previous section and the value is 0. The value is determined by the lenght attribute of the string, whether the number exceeds 4 digits.

 

 

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.