1 2 3 4 5 6 7 8 9=100 fill in +=*/so the result =100 without parentheses
There seems to be no particularly good general solution, programming poor to lift a bit
int algorithm_100 ()
{
int i,j,n,nret=0;
float Fnum[32],fres;
TCHAR szoperate[]= "+-x/", szoper[10]={0},sztext[256]={0};
for (i=0; i<65536; i++)//8 operators, 4 possible, 8 4-square =65536
{
n = 0;
Fnum[0] = 1;
for (j=0; j<8; j + +)
{
SZOPER[J] = szoperate[(i>> (j*2)) &3];
if (szoper[j] = = ' x ')
{
Fnum[n] *= (j+2);
} else if (szoper[j] = = '/')///
{
Fnum[n]/= (j+2);
} else//+-
{
Fnum[++n] = Szoper[j];
Fnum[++n] = j+2;
}
}
Fres = fnum[0];
CAC Result
for (j=1; j<n; j+=2)
{
if (fnum[j] = = ' + ')//+
Fres + = fnum[j+1];
Else
Fres-= fnum[j+1];
}
if (fres = = 100)
{
for (j=0; j<9; j + +)
{
Sztext[j*2+0] = ' 1 ' +j;
SZTEXT[J*2+1] = Szoper[j];
}
TRACE (Sztext);//output result
nret++;
}
}
return nret;
}
The results are as follows:
1x2x3x4+5+6+7x8+9
1-2+3x4x5+6x7+8-9
1-2+3x4x5-6+7x8-9
1+2+3+4+5+6+7+8x9 one of the most easily thought-out
1x2x3+4+5+6+7+8x9
1-2x3+4x5+6+7+8x9
1+2x3+4x5-6+7+8x9
1-2x3-4+5x6+7+8x9
1+2-3x4+5x6+7+8x9
1+2x3x4x5/6+7+8x9
1x2x3x4+5+6-7+8x9
1-2x3-4-5+6x7+8x9
1+2-3x4-5+6x7+8x9
1+2+3-4x5+6x7+8x9
1x2x3-4x5+6x7+8x9
Math problem in primary school a 1 ... 9=100