package xcrj.kchalgorithm.bruteForce;
/**
* 在象棋算式里,不同的棋子代表不同的数,有以下算式,设计一个算法求这些棋子各代表哪些数字。
* 兵 炮 马 卒
* +
* 兵 炮 车 卒
* --------------
* 车 卒 马 兵 卒
*/
public class ChessFormula {
public static void main(String[] args) {
// a是兵
for (int a = 0; a < 10; a++) {
// b是炮
for (int b = 0; b < 10; b++) {
// c是马
for (int c = 0; c < 10; c++) {
// d是卒
for (int d = 0; d < 10; d++) {
// e是车
for (int e = 0; e < 10; e++) {
// 车 卒 马 兵 卒 分别代表不同的数字,互不相同,从5个中选两个相等的,共有C^2_5
if (a == b) continue;
if (a == c) continue;
if (a == d) continue;
if (a == e) continue;
if (b == c) continue;
if (b == d) continue;
if (b == e) continue;
if (c == d) continue;
if (c == e) continue;
if (d == e) continue;
if ((a * 1000 + b * 100 + c * 10 + d) + (a * 1000 + b * 100 + e * 10 + d) == (e * 10000 + d * 1000 + c * 100 + a * 10 + d))
System.out.println("兵:" + a + " 炮:" + b + " 马:" + c + " 卒:" + d + " 车:" + e);
}
}
}
}
}
}
}
蛮力法/兵炮车卒马分别代表不同的数字
于 2022-06-03 20:40:50 首次发布