Topic Link: UVa 725
Meaning
Enter a positive integer n that prints all expressions, such as abcde/fghij=n, in a small to large order, where a~j happens to be a permutation of the number 0~9 (can have a leading 0), 2<=n<=79.
Analysis:
Violent enumeration. 5 for loop, then check it out.
CODE:
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <
Algorithm> #include <cmath> using namespace std;
int n, t1, T2, vis[10], bad, a[5], i[5], first=1;
int main () {#ifdef local freopen ("In.txt", "R", stdin);
Freopen ("OUT.txt", "w", stdout);
#endif while (CIN >> N) {if (n = 0) break;
if (a), 0;
else Putchar (' \ n ');
int flag = 0; for (i[0] = 0; I[0] < i[0] + +) {for (i[1] = 0; I[1] < i[1] + +) {for (i[2] = 0; I[2] < 10;
I[2] + +) {for (i[3] = 0 I[3] < i[3] + +) {for (i[4] = 0; I[4] < i[4] + +) {
Bad = 0;
for (int j = 0; J < 5; J +) {for (int k = j + 1; k < 5; k++) {if (i[j] = i[k])
{bad = 1;
Break
} if (bad) break;
} if (bad) continue;
memset (Vis, 0, sizeof (VIS)); T1 = I[0] * 10000 + i[1] * 1000 + i[2] * + i[3] * + i[4];
if (t1%n) continue;
t2 = t1/n;
for (int j = 0; J < 5; J +) {a[j] = t2% 10;
T2/= 10;
VIS[A[J]] = 1;
VIS[I[J]] = 1;
Bad = 0;
for (int j = 0; J < + j) {if (vis[j] = = 0) {bad = 1;
Break
} if (bad) continue;
printf ("%5d/%05d =%d\n", t1, t1/n, N);
flag = 1;
}} if (!flag) printf ("There are no solutions for%d.\n", N);
return 0; }