@fyywy520
2015-08-27T12:11:37.000000Z
字数 807
阅读 2036
数学
public class MathTest {
public static void main(String[] args) throws Exception {
int ynterofxis[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
cal(ynterofxis, 0, ynterofxis.length - 1);
}
public static void cal(int[] buf, int start, int end) {
if (start == end) {// 递归至最后一位时开始计算
int y, n, t, e, r, o, f, x, i, s;
y = buf[0];
n = buf[1];
t = buf[2];
e = buf[3];
r = buf[4];
o = buf[5];
f = buf[6];
x = buf[7];
i = buf[8];
s = buf[9];
// 计算题设表达式是否成立
boolean equal = (n + 10 * e + 100 * t) * 2 + (y + 10 * t + 100 * r + 1000 * o + 10000 * f) == (y + 10 * t + 100 * x + 1000 * i + 10000 * s);
if (equal) { // 输出结果
System.out.print("ynterofxis = ");
for (int j = 0; j <= buf.length - 1; j++) {
System.out.print(buf[j]);
}
System.out.println();
}
} else {// 多个数字全排列
for (int i = start; i <= end; i++) {
int temp = buf[start];// 交换数组第一个元素与后续的元素
buf[start] = buf[i];
buf[i] = temp;
cal(buf, start + 1, end);// 后续元素递归全排列
temp = buf[start];// 将交换后的数组还原
buf[start] = buf[i];
buf[i] = temp;
}
}
}
}
ynterofxis = 6085792413