正文
增加 3 行删除 3 行
52 行未改动5354555657585960612 行未改动6465666768697071727374755 行未改动52 行未改动## 完整代码```cpp#include <bits/stdc++.h>const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1};using namespace std; int a[32][32], b[32][32], n;void dfs(int nx, int ny) {if (nx < 0 || nx > n + 1 || ny < 0 || ny > n + 1 || a[nx][ny] != 0) return ;a[nx][ny] = 1; for (int i = 0; i < 4; i++) { dfs(nx + dx[i], ny + dy[i]); }2 行未改动cin >> n; for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++) { cin >> b[i][j];a[i][j] = (b[i][j] == 0 ? 0 : 2);}dfs(0, 0);for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) cout << (a[i][j] == 0 ? 2 : b[i][j]) << " ";cout << '\n';}}```5 行未改动52 行未改动5354555657585960612 行未改动6465666768697071727374755 行未改动52 行未改动## 完整代码```cpp#include <bits/stdc++.h>const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1};using namespace std; int a[32][32], b[32][32], n;void dfs(int nx, int ny) {if (nx < 0 || nx > n + 1 || ny < 0 || ny > n + 1 || a[nx][ny] != 0) return ;a[nx][ny] = 1; for (int i = 0; i < 4; i++) { dfs(nx + dx[i], ny + dy[i]); }2 行未改动cin >> n; for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++) { cin >> b[i][j];a[i][j] = (b[i][j] == 0 ? 0 : 2);}dfs(0, 0);for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) cout << (a[i][j] == 0 ? 2 : b[i][j]) << " ";cout << '\n';}}```5 行未改动