#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
bool yon(int a, int b)
{
int tmp_a = a, tmp_b = b;
int num_a[10], num_b[10];
//int many_a, many_b;
memset(num_a, 0, sizeof(num_a)); memset(num_b, 0, sizeof(num_b));
for (int i = 0;; i++)
{
num_a[i] = tmp_a % 10;
tmp_a /= 10;
//many_a = i;
if (!tmp_a)break;
}
tmp_a = a;
for (int i = 0;; i++)
{
num_b[i] = tmp_b % 10;
tmp_b /= 10;
//many_b = i;
if (!tmp_b)break;
}
tmp_b = b;
int nna[10], nnb[10];
bool treu=1;
memset(nna, 0, sizeof(nna)); memset(nnb, 0, sizeof(nnb));
for (int i = 0; i < 10; i++)
for (int j = 0; j < 5; j++)
{
if (num_a[j] == i)nna[i]++;
if (nna[i] > 1) {treu = 0; break;}
}
for (int i = 0; i < 10; i++)
for (int j = 0; j < 5; j++)
{
if (num_b[j] == i)nnb[i]++;
if (nnb[i] > 1) {treu = 0; break;}
}
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
{
if (num_a[i] == num_b[j]) { treu = 0; break; }
}
return treu;
}
int main()
{
int num;
bool key = 1;
while (scanf("%d", &num) == 1 && num)
{
if (!key)printf("\n");
key=0;
for (int i = 1234; i < 50010; i++)
{
if (i*num > 99999)break;
if (yon(i,i*num))
{
key = 1;
printf("%d / %05d = %d\n", i*num, i, num);
}
}
if(!key)printf("There are no solutions for %d.\n",num);
}
}
這題測資範圍不多
不知道是哪裡出了問題@@