结果:
5796/12=483
5346/18=297
5346/27=198
4396/28=157
7254/39=186
5796/42=138
7632/48=159
思路:取两位数(12-98)和三位数(123-987)的乘积是一个四位数时,判定三个数字是否遍历数字“1-9”,若是,OK!
#include <iostream.h>int main()
{
int array[9] = {0};
int a,b,c,d,sum=2;
a = b = c = d = sum = 0;bool bIs = true;
for(int i = 12;i<=98;i++)
for(int j = 123;j<=987;j++)
{
sum = i*j;
if(sum > 9876)
{
j = 988;
break;
}
if(sum>=1234&&sum<=9876)
{
a=i/10,b=i%10;
if(a!=0&&b!=0)
array[a-1] = array[b-1] = 1;
a=j/100,b=(j-a*100)/10,c=j%10;
if(a!=0&&b!=0&&c!=0)
array[a-1] = array[b-1] = array[c-1] = 1;
a=sum/1000,b=(sum-a*1000)/100,c=(sum-a*1000-b*100)/10,d=sum%10;
if(a!=0&&b!=0&&c!=0&&d!=0)
array[a-1] = array[b-1] = array[c-1] = array[d-1] = 1;
for(int m = 0;m<9;m++)
if(array[m] == 0)
{
bIs = false;
break;
}
if(bIs)
{
cout<<sum<<\"/\"<<i<<\"=\"<<j<<endl;
}
bIs = true;
for(int m = 0;m<9;m++)
array[m] = 0;
}
}
return 0;
}