return;
}
}
}
}
}
}
}
}
//tree2 = new int[7];
for (int h = 0; h < 4; h++) {
for (int i = 0; i < 4; i++) {
if (i == h) {
continue;
}
for (int j = 0; j < 4; j++) {
if (j == i || j == h) {
continue;
}
for (int k = 0; k < 4; k++) {
if (k == h || k == i || k == j) {
continue;
}
tree1[3] = data[h];
tree1[4] = data[i];
tree1[5] = data[j];
tree1[6] = data[k];
// 填充操作符
for (int m = PLUS; m <= DIV; m++) {
for (int n = PLUS; n <= DIV; n++) {
for (int o = PLUS; o <= DIV; o++) {
tree1[0] = m;
tree1[1] = n;
tree1[2] = o;
String t[] = new String[3];
for (int z = 0; z < 3; z++) {
switch (tree1[z]) {
t[z] = "+";
break;
case MINUS:
t[z] = "-";
break;
case MULT:
t[z] = "*";
break;
case DIV:
t[z] = "/";
break;
}
}
// 目前为止tree数组全部已赋值
String postexpr = tree1[4] + " " + tree1[3]
+ " " + t[1] + " " + tree1[6] + " "
+ tree1[5] + " " + t[2] + " " + t[0];
String result = CalculatorUtils
.calculateReversePolish(postexpr);
if (Double.parseDouble((result)) == 24.0) {
expr = "((" + tree1[3] + t[1] + tree1[4]
+ ")" + t[0] +"("+tree1[5]
+ t[2] + tree1[6] + "))";
System.out.println(expr);
return;
}
}
}
}
}
}
}
}
expr = "无解";
}
pub