class Check {
final static int TARGET_NUM = 100;
final static int stacksize = 16;
int[] numStack;
int[] opStack;
int[] numStack2;
int[] opStack2;
int numStackPoint, opStackPoint, numStack2Point, opStack2Point;
Check() {
numStack = new int[stacksize];
opStack = new int[stacksize];
numStack2 = new int[stacksize];
opStack2 = new int[stacksize];
}
void CheckAndOutput(int[] seed) {
boolean minusstartflag = false;
numStackPoint = opStackPoint = numStack2Point = opStack2Point = 0;
numStack[numStackPoint++] = 0;
/* step 1 */
for (int i = 0; i < 9; i++) {
switch (seed[i]) {
case 0: /* concat */
int t = numStack[--numStackPoint];
if (!minusstartflag)
numStack[numStackPoint++] = t * 10 + (i + 1);
else
numStack[numStackPoint++] = t * 10 - (i + 1);
break;
case 1: /* + */
opStack2[opStack2Point++] = opStack[opStackPoint++] = 1;
numStack2[numStack2Point++] = numStack[numStackPoint - 1];
numStack[numStackPoint++] = i + 1;
minusstartflag = false;
break;
case 2: /* - */
if (i == 0) {
minusstartflag = true;
numStack[numStackPoint - 1] = -1;
} else {
opStack2[opStack2Point++] = opStack[opStackPoint++] = 2;
numStack2[numStack2Point++] = numStack[numStackPoint - 1];
numStack[numStackPoint++] = i + 1;
minusstartflag = false;
}
break;
}
} /* for */
numStack2[numStack2Point++] = numStack[numStackPoint - 1];
ReverseStack(numStack, numStackPoint);
ReverseStack(opStack, opStackPoint);
/* step 2b */
while (opStackPoint > 0) {
switch (opStack[--opStackPoint]) {
case 1: /* + */
int t1 = numStack[--numStackPoint];
int t2 = numStack[--numStackPoint];
numStack[numStackPoint++] = t1 + t2;
break;
case 2: /* - */
t1 = numStack[--numStackPoint];
t2 = numStack[--numStackPoint];
numStack[numStackPoint++] = t1 - t2;
break;
}
}
int answer = numStack[0];
/* step 3 */
if (answer == TARGET_NUM) {
int num_sp = 0, op_sp = 0;
if (minusstartflag) {
op_sp++;
}
while (num_sp < numStack2Point) {
System.
out.
print(numStack2
[num_sp
++]); if (op_sp < opStack2Point)
switch (opStack2[op_sp++]) {
case 1:
case 2:
case 3:
case 4:
}
} /* while */
System.
out.
println(" = " + answer
); } /* if TARGET_NUM */
} /* method */
static void ReverseStack(int[] array, int n) { for (int i = 0; i < n - i - 1; i++) myswap(array, i, n - i - 1); }
static void myswap(int[] array, int a, int b) { int t; t = array[a]; array[a] = array[b]; array[b] = t; }
}
class Main {
public static void main
(String[] args
) { Factory factory = new Factory();
int[] seed;
Check check = new Check();
while (factory.getSeed(seed = new int[9])) {
check.CheckAndOutput(seed);
}
}
}
class Factory {
static int[] seed;
boolean stopflag;
Factory() {
seed = new int[9];
stopflag = false;
for (int i = 0; i < 9; i++) seed[i] = 0;
}
private boolean next() {
int idx = 8;
if (stopflag)
return !stopflag;
do {
boolean cy = false;
if (seed[idx]++ >= 2) {
seed[idx] = 0;
cy = true;
}
while (idx > 0 ) {
--idx;
if (cy == true)
if (seed[idx]++ >= 2) {
seed[idx] = 0;
cy = true;
} else {
cy = false;
}
}
if (cy == true)
stopflag = true;
} while (seed[0] != 0 && seed[0] != 2);
return !stopflag;
}
public boolean getSeed(int[] seed) {
boolean flag;
flag = this.next();
for (int i = 0; i < 9; i++)
seed[i] = this.seed[i];
return flag;
}
}
/* end */