Skip to content

Instantly share code, notes, and snippets.

@Thiago4532
Created September 4, 2019 20:51
Show Gist options
  • Save Thiago4532/24f9daf77d1902d71f1b0d8708cd8764 to your computer and use it in GitHub Desktop.
Save Thiago4532/24f9daf77d1902d71f1b0d8708cd8764 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
char mat[maxn][maxn];
void dfs(int x, int y){
if (mat[x+1][y]=='.'){
mat[x+1][y]='o';
dfs(x+1, y);
}
else if (mat[x+1][y]=='#'){
if (mat[x][y-1]=='.'){
mat[x][y-1]='o';
dfs(x, y-1);
}
if (mat[x][y+1]=='.'){
mat[x][y+1]='o';
dfs(x, y+1);
}
}
}
int main() {
int n, m;
cin >> n >> m;
int inii, inij;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> mat[i][j];
if(mat[i][j]=='o'){
inii=i;
inij=j;
}
}
}
dfs(inii, inij);
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cout << mat[i][j];
}
cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment