大佬们帮帮我吧!
#include <bits/stdc++.h>
using namespace std;
int r, c,dx[4] = {0, 1, 0, -1},dy[4] = {-1, 0, 1, 0};
char s[114][78];
vector<pair<int, int>> ans;
void dfs(int x, int y) {
if (x == r && y == c) {
return;
}
for (int i = 0; i < 4; i++) {
int xx = x + dx[i];
int yy = y + dy[i];
if (xx >= 1 && yy >= 1 && xx <= r && yy <= c && s[xx][yy] == '.') {
s[xx][yy] = '*';
ans.push_back({xx, yy});
dfs(xx, yy);
}
}
}
int main() {
cin >> r >> c;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
cin >> s[i][j];
}
}
s[1][1]='*';
ans.push_back({1,1});
dfs(1, 1);
for (int i = 0; i < ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << endl;
}
return 0;
}