DivisionWrite A program, finds and displays all pairs of 5-digit numbers, between them use the digits 0 through 9 once Each, such this first number divided by the second are equal to an integer N, where
. That's,
Abcde/fghij = N
Where each letter represents a different digit. The first digit 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 was to terminate the program.
Output
Your program has to display all qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator ).
Your output should is in the following general form:
Xxxxx/xxxxx = N
Xxxxx/xxxxx = N
.
.
In case there is no pairs of numerals satisfying the condition, you must write ' there is no solutions for N. '. Separate the output for both different values of N by a blank line.
Sample Input
61
62
0
Sample Output
There is no solutions for 61.
79546/01283 = 62
94736/01528 = 62
Main topic: Enter a positive integer n, which requires an expression from small to large output shape such as Abcde/fghij = N.
The a~f is required to be a digital 0~9 and cannot be duplicated (0 in front).
Idea: If a b c D e F g h i j all traverse, the complexity is 10!, no need, direct enumeration
f g H i j, then calculate a b C D e, to determine whether there are duplicate numbers.
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace Std;int Main () {int sum,num,n,j; int a,b,c,d,e; int f,g,h,l,m; int x[10],ok = 0; while (~SCANF ("%d", &n) && N) {if (ok = = 0) ok = 1; else printf ("\ n"); sum = 0; for (int i = 1234; I <= 98765; i++) {memset (x,0,sizeof (x)); A = I%10,b = I/10%10,c = I/100%10,d = I/1000%10,e = i/10000%10; num = i*n; if (num>98765) break; f = num%10,g = Num/10%10,h = num/100%10,l = Num/1000%10,m = num/10000%10; x[a]++,x[b]++,x[c]++,x[d]++,x[e]++; x[f]++,x[g]++,x[h]++,x[l]++,x[m]++; for (j = 0; J <= 9; j + +) if (x[j]>1) break; if (j==10) {printf ("%d%d%d%d%d/%d%d%d%d%d =%d\n", m,l,h,g,f,e,d,c,b,a,n); sum++; } else continue; } if (sum==0) printf ("There is no solutions for%d.\n", N); } return 0;}
UVA725 Division "Enumeration"