#include <stdio.h>
#include <stdlib.h>
#define N 9
char ops[] = "+-*/";
void
nToExpr(int n, int *v, char *op)
{
int i;
for (i = 0; i < N; i++) {
v[i] = i + 1;
op[i] = ops[n % 4];
n /= 4;
}
op[N - 1] = '=';
}
void
pp(int *v, char *op)
{
int i;
for (i = 0; i < N; i++)
}
int
calc(int *v, char *op)
{
int r, i, t, flg;
char w[10];
/* 空白処理 */
/* for (i = N - 1; i >= 0; i--) { */
/* if (op[i] == ' ') { */
/* sprintf(w, "%d%d", v[i], v[i + 1]); */
/* v[i] = atoi(w); */
/* op[i] = '+'; */
/* v[i + 1] = 0; */
/* } */
/* } */
/* '-'を'+'に書き換え */
for(i=0; i<N; i++) {
if(op[i]=='-') {
v[i+1]=-v[i+1];
op[i]='+';
}
}
/* '/'と'*'とを 入れ替 */
do {
flg = 0;
for (i = 0; i < N - 1; i++) {
if ((op[i] == '/') && (op[i + 1] == '*')) {
flg = 1;
op[i] = '*';
op[i + 1] = '/';
t = v[i + 1];
v[i + 1] = v[i + 2];
v[i + 2] = t;
}
}
} while (flg);
/* '*'、'/'を先に計算 */
for (i = 0; i < N - 1; i++) {
switch (op[i]) {
case '*':
v[i+1]*=v[i];
v[i]=0;
op[i]='+';
break;
case '/':
v[i+1]=v[i]/v[i+1];
v[i]=0;
op[i]='+';
break;
default:
break;
}
}
r=v[0];
for (i = 0; i < N - 1; i++) {
r+=v[i+1];
}
return r;
}
int
main()
{
int v[N], i, n;
char op[N];
n = 1;
i = sizeof(op) - 1;
while (i--)
n *= sizeof(ops) - 1;
while (n--) {
nToExpr(n, v, op);
/* pp(v, op); */
/* printf("%d\n",calc(v, op)); */
if(calc(v, op)==100) {
nToExpr(n, v, op);
pp(v,op);
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2RlZmluZSBOIDkKCmNoYXIgICAgICAgICAgICBvcHNbXSA9ICIrLSovIjsKCnZvaWQKblRvRXhwcihpbnQgbiwgaW50ICp2LCBjaGFyICpvcCkKewogIGludCAgICAgICAgICAgICBpOwogIGZvciAoaSA9IDA7IGkgPCBOOyBpKyspIHsKICAgIHZbaV0gPSBpICsgMTsKICAgIG9wW2ldID0gb3BzW24gJSA0XTsKICAgIG4gLz0gNDsKICB9CiAgb3BbTiAtIDFdID0gJz0nOwp9Cgp2b2lkCnBwKGludCAqdiwgY2hhciAqb3ApCnsKICBpbnQgICAgICAgICAgICAgaTsKICBmb3IgKGkgPSAwOyBpIDwgTjsgaSsrKQogICAgcHJpbnRmKCIlZCVjICIsIHZbaV0sIG9wW2ldKTsKICBwdXRjaGFyKCdcbicpOwp9CgppbnQKY2FsYyhpbnQgKnYsIGNoYXIgKm9wKQp7CiAgaW50ICAgICAgICAgICAgIHIsIGksIHQsIGZsZzsKICBjaGFyICAgICAgICAgICAgd1sxMF07CiAgLyog56m655m95Yem55CGICovCgogIC8qICAgZm9yIChpID0gTiAtIDE7IGkgPj0gMDsgaS0tKSB7ICovCiAgLyogICAgIGlmIChvcFtpXSA9PSAnICcpIHsgKi8KICAvKiAgICAgICBzcHJpbnRmKHcsICIlZCVkIiwgdltpXSwgdltpICsgMV0pOyAqLwogIC8qICAgICAgIHZbaV0gPSBhdG9pKHcpOyAqLwogIC8qICAgICAgIG9wW2ldID0gJysnOyAqLwogIC8qICAgICAgIHZbaSArIDFdID0gMDsgKi8KICAvKiAgICAgfSAqLwogIC8qICAgfSAqLwoKICAvKiAnLSfjgpInKyfjgavmm7jjgY3mj5vjgYggKi8KICBmb3IoaT0wOyBpPE47IGkrKykgewogICAgaWYob3BbaV09PSctJykgewogICAgICB2W2krMV09LXZbaSsxXTsKICAgICAgb3BbaV09JysnOwogICAgfQogIH0KCiAgLyogJy8n44GoJyon44Go44KSIOWFpeOCjOabvyAqLwogIGRvIHsKICAgIGZsZyA9IDA7CiAgICBmb3IgKGkgPSAwOyBpIDwgTiAtIDE7IGkrKykgewogICAgICBpZiAoKG9wW2ldID09ICcvJykgJiYgKG9wW2kgKyAxXSA9PSAnKicpKSB7CiAgICAgICAgZmxnID0gMTsKICAgICAgICBvcFtpXSA9ICcqJzsKICAgICAgICBvcFtpICsgMV0gPSAnLyc7CiAgICAgICAgdCA9IHZbaSArIDFdOwogICAgICAgIHZbaSArIDFdID0gdltpICsgMl07CiAgICAgICAgdltpICsgMl0gPSB0OwogICAgICB9CiAgICB9CiAgfSB3aGlsZSAoZmxnKTsKCiAgLyogJyon44CBJy8n44KS5YWI44Gr6KiI566XICovCiAgZm9yIChpID0gMDsgaSA8IE4gLSAxOyBpKyspIHsKICAgIHN3aXRjaCAob3BbaV0pIHsKICAgIGNhc2UgJyonOgogICAgICB2W2krMV0qPXZbaV07CiAgICAgIHZbaV09MDsKICAgICAgb3BbaV09JysnOwogICAgICBicmVhazsKICAgIGNhc2UgJy8nOgogICAgICB2W2krMV09dltpXS92W2krMV07CiAgICAgIHZbaV09MDsKICAgICAgb3BbaV09JysnOwogICAgICBicmVhazsKICAgIGRlZmF1bHQ6CiAgICAgIGJyZWFrOwogICAgfQogIH0KCiAgcj12WzBdOwogIGZvciAoaSA9IDA7IGkgPCBOIC0gMTsgaSsrKSB7CiAgICByKz12W2krMV07CiAgfQoKICByZXR1cm4gcjsKfQoKCmludAptYWluKCkKewogIGludCAgICAgICAgICAgICB2W05dLCBpLCBuOwogIGNoYXIgICAgICAgICAgICBvcFtOXTsKCiAgbiA9IDE7CiAgaSA9IHNpemVvZihvcCkgLSAxOwogIHdoaWxlIChpLS0pCiAgICBuICo9IHNpemVvZihvcHMpIC0gMTsKCiAgd2hpbGUgKG4tLSkgewogICAgblRvRXhwcihuLCB2LCBvcCk7CgogICAgLyogICAgIHBwKHYsIG9wKTsgKi8KICAgIC8qICAgICBwcmludGYoIiVkXG4iLGNhbGModiwgb3ApKTsgKi8KCiAgICBpZihjYWxjKHYsIG9wKT09MTAwKSB7CiAgICAgIG5Ub0V4cHIobiwgdiwgb3ApOwogICAgICBwcCh2LG9wKTsKICAgIH0KCiAgfQoKICByZXR1cm4gMDsKfQ==