回复 4楼 liyue6822532
是的,不小心把24写成了25(昨天是用手机回复的)
火柴一种才25种可能,直接给出答案行不行?
程序代码:
#include <stdio.h>
int main( void )
{
const unsigned results[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,8,9,6,9,29,39,38,65,88,128 };
for( unsigned n; scanf("%u",&n)==1 && n<=24; )
printf( "%u\n", results[n] );
return 0;
}
如果不行的话,把计算过程也贴出来
程序代码:
#include <stdio.h>
int main( void )
{
// 算出1000以内的每个数需要的火柴数
unsigned sticks[1000] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
for( unsigned i=10; i!=1000; ++i )
sticks[i] = sticks[i/10] + sticks[i%10];
// 算出火柴数小于等于24的所有等式数目
unsigned results[25] = { 0 };
for( unsigned a=0; a!=1000; ++a )
for( unsigned b=0; a+b!=1000; ++b )
{
unsigned sum = getsticks(a)+getsticks(b)+getsticks(a+b)+4;
if( sum <= 24 )
++results[sum];
}
// 和第一段代码相同
for( unsigned n; scanf("%u",&n)==1 && n<=24; )
printf( "%u\n", results[n] );
return 0;
}