UV 725, uva725

Source: Internet
Author: User

UV 725, uva725

Description

 

Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits0Through9Once each, such that the first number divided by the second is equal to an integerN, Where. That is,

 

Abcde/fghij =N

Where each letter represents a different digit. The first digit of one of the numerals is allowed to be zero.

 

Input Each line of the input file consists of a valid integer N. An input of zero is to terminate the program.

 

Output Your program have to display ALL qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator ).

Your output shocould be in the following general form:

 

Xxxxx/xxxxx =N

Xxxxx/xxxxx =N

.

.

 

In case there are no pairs of numerals satisfying the condition, you must write''There are no solutionsN.". Separate the output for two different valuesNBy a blank line.

 

Sample Input
61620

 

Sample Output
There are no solutions for 61.79546 / 01283 = 6294736 / 01528 = 62

 

 

 

Enter a number n and output its abcde/fghij = n Type Sub-Statement from small to large (Note that there can be leading 0 spaces) a-j is an array ranging from 0 to 9. If not, output There are no solutions for 61. format requirements: Change the rows for each group of cases. (The output format is also RLGL)

 

 

Solution: enumeration, but it is from the dividend enumeration, and the Division is calculated by multiplication. Then, you only need to judge whether the divisor is greater than 100000, and whether a-j is equal.

 

 

The Code is as follows: (if you want to write it yourself, you will not mark it, but you still don't stick to it. You still read other people's blogs and then copy it .)

 

To ask a question, use memse (m, 0, sizeof (m) to clear the array m. Why must it be sizeof (m)? The length of m cannot be 10, because when I use 10, even the cases won't work ....

Please tell me, that's right. This is what I cook... (⊙) B

 

 

 

 

1 # include <stdio. h> 2 # include <cstring> 3 int m [10]; 4 int panduan (int a, int B) 5 {6 if (a> 100000) 7 return 0; 8 memset (m, 0, sizeof (m); 9 // for (int I = 0; I <10; I ++) 10 // m [I] = 0; 11 if (B <10000) 12 m [0]; // It is easy to forget 13 while () 14 {15 m [a % 10] = 1; // each digit is marked with 16 a = a/10; // if it is marked, a 17} 18 while (B) 19 {20 m [B % 10] = 1; 21 B = B/10 is removed; 22} 23 int sum = 0; 24 for (int j = 0; j <10; j ++) 25 sum + = m [j]; 26 return sum = 10; // If sum is equal to 10, 27} 28 int main () 29 {30 int n, k = 0; 31 while (scanf ("% d", & n) is returned) = 1 & n) 32 {33 if (k> 0) printf ("\ n"); k ++; // The output lattice must be 34 int flag = 1; 35 for (int I = 1234; I <1000000; I ++) 36 {37 if (panduan (n * I, I )) 38 {39 printf ("% d/% 05d = % d \ n", I * n, I, n); 40 flag = 0; 41} 42} 43 if (flag) 44 printf ("There are no solutions for % d. \ n ", n); 45 46} 47 return 0; 48}

 

 

 

 


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.