#include <stdio.h>
#include <string.h>
#define NUM 6561 // 3^8
const char kigou[] = {'+','-','*'};
void print(int en[8])
{
int i;
for (i = 0; i < 8; i++)
printf("%1d%1c", i+1,kigou[en[i]]);
printf("9=100\n");
}
void eval(int en[8])
{
int num[9] = {1,2,3,4,5,6,7,8,9};
int i, pm, sum;
for (i = 0; i < 8; i++) {
if (en[i] == 2) {
num[i+1] = num[i] * num[i+1];
num[i] = 0;
}
}
for (i = 0; i < 8; i++) {
if (num[i] != 0) {
sum = num[i];
break;
}
}
for (; i < 8; i++) {
if (en[i] == 0) {
pm = 1;
} else if (en[i] == 1) {
pm = -1;
}
sum += num[i+1] * pm;
}
if (sum == 100) {
print(en);
}
}
void form(int en[8], int num)
{
int i;
for (i = 0; i < 8; i++) {
int y = num / 3;
en[i] = num % 3;
num = y;
}
}
int main()
{
int en[8];
int i;
for (i=0; i<NUM; i++) {
memset(en, 0, sizeof(en));
form(en,i);
eval(en);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCiNkZWZpbmUgTlVNIDY1NjEgLy8gM144CmNvbnN0IGNoYXIga2lnb3VbXSA9IHsnKycsJy0nLCcqJ307Cgp2b2lkIHByaW50KGludCBlbls4XSkKewogICAgaW50IGk7CiAgICBmb3IgKGkgPSAwOyBpIDwgODsgaSsrKQogICAgICAgIHByaW50ZigiJTFkJTFjIiwgaSsxLGtpZ291W2VuW2ldXSk7CiAgICBwcmludGYoIjk9MTAwXG4iKTsKfQoKdm9pZCBldmFsKGludCBlbls4XSkKewogICAgaW50IG51bVs5XSA9IHsxLDIsMyw0LDUsNiw3LDgsOX07CiAgICBpbnQgaSwgcG0sIHN1bTsKICAgIGZvciAoaSA9IDA7IGkgPCA4OyBpKyspIHsKICAgICAgICBpZiAoZW5baV0gPT0gMikgewogICAgICAgICAgICBudW1baSsxXSA9IG51bVtpXSAqIG51bVtpKzFdOwogICAgICAgICAgICBudW1baV0gPSAwOwogICAgICAgIH0KICAgIH0KICAgIGZvciAoaSA9IDA7IGkgPCA4OyBpKyspIHsKICAgICAgICBpZiAobnVtW2ldICE9IDApIHsKICAgICAgICAgICAgc3VtID0gbnVtW2ldOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9CiAgICBmb3IgKDsgaSA8IDg7IGkrKykgewogICAgICAgIGlmIChlbltpXSA9PSAwKSB7CiAgICAgICAgICAgIHBtID0gMTsKICAgICAgICB9IGVsc2UgaWYgKGVuW2ldID09IDEpIHsKICAgICAgICAgICAgcG0gPSAtMTsKICAgICAgICB9CiAgICAgICAgc3VtICs9IG51bVtpKzFdICogcG07CiAgICB9CiAgICBpZiAoc3VtID09IDEwMCkgewogICAgICAgIHByaW50KGVuKTsKICAgIH0KfQp2b2lkIGZvcm0oaW50IGVuWzhdLCBpbnQgbnVtKQp7CiAgICBpbnQgaTsKICAgIGZvciAoaSA9IDA7IGkgPCA4OyBpKyspIHsKICAgICAgICBpbnQgeSA9IG51bSAvIDM7CiAgICAgICAgZW5baV0gPSBudW0gJSAzOwogICAgICAgIG51bSA9IHk7CiAgICB9Cn0KCmludCBtYWluKCkKewogICAgaW50IGVuWzhdOwogICAgaW50IGk7CiAgICBmb3IgKGk9MDsgaTxOVU07IGkrKykgewogICAgICAgIG1lbXNldChlbiwgMCwgc2l6ZW9mKGVuKSk7CiAgICAgICAgZm9ybShlbixpKTsKICAgICAgICBldmFsKGVuKTsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==