输入正整数n, 按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a-j恰好为0-9的一个排列(可以有前导0), 2<= n <= 79;
样例
62
79646 / 01283 = 62
94736 / 01528 = 62
#include<bits/stdc++.h>
using namespace std;
int use[10];
int judge(int x, int y)
{
memset(use, 0, sizeof(use));
if(x > 98765)
return 0;
if(y < 10000)
use[0] = 1;
while(x || y)
{
int id = x % 10;
x = x / 10;
use[id] = 1;
id = y % 10;
y = y / 10;
use[id] = 1;
}
int sum = 0;
for(int i = 0; i < 10; i++)
if(use[i])
sum++;
if(sum == 10)
return 1;
return 0;
}
int main()
{
int n;
int flag = 0;
while(~scanf("%d", &n),n)
{
int cas = 0;
if(flag)
printf("\n");
flag = 1;
for(int i = 1234; i < 100000; i++)
{
if(judge(i*n, i))
{
cas++;
printf("%05d / %05d = %d\n", i * n, i, n);
}
}
if(cas == 0)
printf("There are no solutions for %d.\n",n);
}
}