B DEF
A + --- + ------- = 10
C GHI
这个算式中A~I代表1~9的数字,不同的字母代表不同的数字。
比如:
6+8/3+952/714 就是一种解法,
5+3/1+972/486 是另一种解法。
这个算式一共有多少种解法?
注意:你提交应该是个整数,不要填写任何多余的内容或说明性文字
答案:29
#include <stdio.h>
int main()
{
int a,b,c,d,e,f,g,h,i;
int m, n, k, t, count;
t = m = n = k = count = 0;
for (a=1; a<10; a++)
{
for (b=1; b<10; b++)
{
if (a == b) continue;
for (c = 1; c<10; c++)
{
if (a ==c || b == c) continue;
for (d = 1; d<10; d++)
{
if (a == d || b == d || c == d) continue;
for (e =1; e<10; e++)
{
if (a==e || b == e || c == e || d == e) continue;
for (f =1; f<10; f++)
{
if (a == f || b == f || c==f || d == f || e == f) continue;
for (g=1; g<10; g++)
{
if (a == g || b == g || c==g || d==g || e==g || f ==g) continue;
for (h=1; h<10; h++)
{
if (a ==h || b ==h || c == h || d == h || e==h || f==h || g==h ) continue;
for (i =1; i<10; i++)
{
if (a ==i || b ==i || c == i || d == i || e==i || f==i || g==i || h==i ) continue;
m = a*c*(g*100+h*10+i);
n = b*(g*100+h*10+i);
k = (d*100+e*10+ f)*c;
t = 10*c*(g*100+h*10+i);
if (m+n+k == t)
count++;
}
}
}
}
}
}
}
}
}
printf("count->%d\n", count);
return 0;
}