将帅不能在一条主线上,直接穷举所有的位置
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
int t = 1;
int b[3][3];
int a[3][3];
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) {
a[i][j] = t;
b[i][j] = t++;
}
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
for (int z = 0; z < 3; ++z)
for (int c = 0; c < 3; ++c) {
if (b[z][c] % 3 != a[i][j])
printf("A=%d,B=%d\n", a[i][j], b[z][c]);
}
return 0;
}