#include <stdio.h>
int main(void)
{
int a[9],b[9],a_ln[9]={0},a_lnf[9]={0};
char k[9]={'+','+','+','+','+','+','+','+','+'};
int i,ac,bc,next,ans,ans_cnt = 0;
while(a_lnf[8]==0/*&&ans_ant<10*/)
{
//初期化
for(i = 0; i < 9; i++)
k[i] = '+';
ac=1;
a_ln[0] = 1;
//つなげる
for(i=1;i<9;i++)
{
if(a_lnf[i-1]==0)//つなげない場合
a_ln[ac++] = i+1;
else//つなげる場合
{
a_ln[ac-1] *= 10;
a_ln[ac-1] += i+1;
}
}
//記号総当たり
while(k[ac-1] == '+'/*&&ans_ant<10*/)
{
//初期化
bc = 1;
next = 1;
for(i = 0; i < ac; i++)
{
a[i] = a_ln[i];
b[i] = 1;
}
b[0] = a[0];
//減算&乗算
for(i = 1; i < ac; i++)
{
switch(k[i-1]){
case '-':
a[i] *= -1;
case '+':
bc++;
default:
b[bc-1] *= a[i];
break;
}
}
//加算
ans = b[0];
for(i = 1; i < bc; i++)
ans += b[i];
//答え合わせ
if(ans==100){
ans_cnt++;
for(i = 0; i < ac-1; i++)
}
//ずらす
for(i = 0; next; i++)
switch(k[i]){
case '+':
k[i] = '-';
next = 0;
break;
case '-':
k[i] = '*';
next = 0;
break;
case '*':
k[i] = '+';
break;
}
}
next = 1;
for(i = 0; next; i++)
if(a_lnf[i]){
a_lnf[i] = 0;
}
else
{
a_lnf[i] = 1;
next = 0;
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiAKaW50IG1haW4odm9pZCkKewogICAgaW50IGFbOV0sYls5XSxhX2xuWzldPXswfSxhX2xuZls5XT17MH07CiAgICBjaGFyIGtbOV09eycrJywnKycsJysnLCcrJywnKycsJysnLCcrJywnKycsJysnfTsKICAgIGludCBpLGFjLGJjLG5leHQsYW5zLGFuc19jbnQgPSAwOwogICAgd2hpbGUoYV9sbmZbOF09PTAvKiYmYW5zX2FudDwxMCovKQogICAgewogICAgICAgIC8v5Yid5pyf5YyWCiAgICAgICAgZm9yKGkgPSAwOyBpIDwgOTsgaSsrKQogICAgICAgICAgICBrW2ldID0gJysnOwoKICAgICAgICBhYz0xOwogICAgICAgIGFfbG5bMF0gPSAxOwogICAgICAgIC8v44Gk44Gq44GS44KLCiAgICAgICAgZm9yKGk9MTtpPDk7aSsrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoYV9sbmZbaS0xXT09MCkvL+OBpOOBquOBkuOBquOBhOWgtOWQiAogICAgICAgICAgICAgICAgYV9sblthYysrXSA9IGkrMTsKICAgICAgICAgICAgZWxzZS8v44Gk44Gq44GS44KL5aC05ZCICiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGFfbG5bYWMtMV0gKj0gMTA7CiAgICAgICAgICAgICAgICBhX2xuW2FjLTFdICs9IGkrMTsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgLy/oqJjlj7fnt4/lvZPjgZ/jgooKICAgICAgICB3aGlsZShrW2FjLTFdID09ICcrJy8qJiZhbnNfYW50PDEwKi8pCiAgICAgICAgewogICAgICAgICAgICAvL+WIneacn+WMlgogICAgICAgICAgICBiYyA9IDE7CiAgICAgICAgICAgIG5leHQgPSAxOwoKICAgICAgICAgICAgZm9yKGkgPSAwOyBpIDwgYWM7IGkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYVtpXSA9IGFfbG5baV07CiAgICAgICAgICAgICAgICBiW2ldID0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBiWzBdID0gYVswXTsKICAgICAgICAgICAgLy/muJvnrpfvvIbkuZfnrpcKICAgICAgICAgICAgZm9yKGkgPSAxOyBpIDwgYWM7IGkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc3dpdGNoKGtbaS0xXSl7CiAgICAgICAgICAgICAgICBjYXNlICctJzoKICAgICAgICAgICAgICAgICAgICBhW2ldICo9IC0xOwogICAgICAgICAgICAgICAgY2FzZSAnKyc6CiAgICAgICAgICAgICAgICAgICAgYmMrKzsKICAgICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICAgICAgYltiYy0xXSAqPSBhW2ldOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIC8v5Yqg566XCiAgICAgICAgICAgIGFucyA9IGJbMF07CiAgICAgICAgICAgIGZvcihpID0gMTsgaSA8IGJjOyBpKyspCiAgICAgICAgICAgICAgICBhbnMgKz0gYltpXTsgCiAgICAgICAgICAgIC8v562U44GI5ZCI44KP44GbCiAgICAgICAgICAgIGlmKGFucz09MTAwKXsKICAgICAgICAgICAgICAgIGFuc19jbnQrKzsKICAgICAgICAgICAgICAgIHByaW50ZigiJWTlgIvnm67jga7nrZTjgYg6IixhbnNfY250KTsKICAgICAgICAgICAgICAgIGZvcihpID0gMDsgaSA8IGFjLTE7IGkrKykKICAgICAgICAgICAgICAgICAgICBwcmludGYoIiVkJWMiLGFfbG5baV0sa1tpXSk7CiAgICAgICAgICAgICAgICBwcmludGYoIiVkXG4iLGFfbG5baV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC8v44Ga44KJ44GZCiAgICAgICAgICAgIGZvcihpID0gMDsgbmV4dDsgaSsrKQogICAgICAgICAgICAgICAgc3dpdGNoKGtbaV0pewogICAgICAgICAgICAgICAgY2FzZSAnKyc6CiAgICAgICAgICAgICAgICAgICAga1tpXSA9ICctJzsKICAgICAgICAgICAgICAgICAgICBuZXh0ID0gMDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgJy0nOgogICAgICAgICAgICAgICAgICAgIGtbaV0gPSAnKic7CiAgICAgICAgICAgICAgICAgICAgbmV4dCA9IDA7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlICcqJzoKICAgICAgICAgICAgICAgICAgICBrW2ldID0gJysnOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBuZXh0ID0gMTsKICAgICAgICBmb3IoaSA9IDA7IG5leHQ7IGkrKykKICAgICAgICAgICAgaWYoYV9sbmZbaV0pewogICAgICAgICAgICAgICAgYV9sbmZbaV0gPSAwOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYV9sbmZbaV0gPSAxOwogICAgICAgICAgICAgICAgbmV4dCA9IDA7CiAgICAgICAgICAgIH0KICAgICB9CiAgICByZXR1cm4gMDsKfQ==