|
发表于 2008-3-18 05:14:33
|
显示全部楼层
如果再加上限定 I = 1,那么有16个解。
void main (void)
{
int i, c, h, d, u, e, r, s, w, n, nn;
for (i = 1; i < 2; i++) // i=1
for (c = 0; c < 10; c++)
for (h = 0; h < 10; h++)
for (d = 1; d < 10; d++) // 最高位不能为零
for (u = 0; u < 10; u++)
for (e = 1; e < 10; e++)
for (r = 0; r < 10; r++)
for (s = 1; s < 10; s++)
for (w = 1; w < 10; w++)
{
if (c != i) // 一个字母只能对应1个数字
if (h != i) if (h != c)
if (d != i ) if (d != c ) if (d != h)
if (u != i ) if (u != c ) if (u != h ) if (u != d)
if (e != i ) if (e != c ) if (e != h ) if (e != d ) if (e != u)
if (r != i ) if (r != c ) if (r != h ) if (r != d ) if (r != u ) if (r != e)
if (s != i ) if (s != c ) if (s != h ) if (s != d ) if (s != u ) if (s != e ) if (s != r)
if (w != i ) if (w != c ) if (w != h ) if (w != d ) if (w != u ) if (w != e ) if (w != r ) if (w != s)
{
n = (i + s - w) * 100 + (c + d + e + e) * 10 + h + u + e + s;
if (!n)
{
nn = w * 100 + i * 10 + r;
printf("i=%d c=%d h=%d d=%d u=%d e=%d r=%d s=%d w=%d\n", i, c, h, d, u, e, r, s, w);
}
}
}
return;
}
这是标准C语言源程序,主要是给大家一个趣味编程的思路。 |
|