#include <cstdio>
#include <cstring>
#include <cstdlib>
int a[10][10];
bool f1[10][10], f2[10][10], f3[10][10];
void print() {
for (int i = 1; i <= 9; i ++ ) {
for (int j = 1; j <= 9; j ++ ) printf("%d ", a[i][j]);
printf("\n");
}
}
void dfs(int x, int y) {
if (y > 9) dfs(x + 1, 1);
if (a[x][y] != 0) {
if (x == 9 && y == 9) {
print();
return ;
}
if (y == 9) dfs(x + 1, 1);
else dfs(x, y + 1);
} else for (int i = 1; i <= 9; i ++ ) if (f1[x][i] && f2[y][i] && f3[(x - 1) / 3 * 3 + (y - 1) / 3 + 1][i]) {
a[x][y] = i;
f1[x][i] = false;
f2[y][i] = false;
f3[(x - 1) / 3 * 3 + (y - 1) / 3 + 1][i] = false;
if (x == 9 && y == 9) print();
if (y == 9) dfs(x + 1, 1);
else dfs(x, y + 1);
a[x][y] = 0;
f1[x][i] = true;
f2[y][i] = true;
f3[(x - 1) / 3 * 3 + (y - 1) / 3 + 1][i] = true;
}
}
int main() {
for (int i = 1; i <= 9; i ++ ) for (int j = 1; j <= 9; j ++ ) scanf("%d", &a[i][j]);
for (int i = 1; i <= 9; i ++ ) for (int j = 1; j <= 9; j ++ ) if (a[i][j]) {
f1[i][a[i][j]] = false;
f2[j][a[i][j]] = false;
int t = (i - 1) / 3 * 3 + (j - 1) / 3 + 1;
f3[t][a[i][j]] = false;
}
dfs(1,1);
return 0;
}//P1784
求解答