代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cstdio>
using namespace std;
char map[35][85];
int v[35][85];
int h;
int w[35];
void dfs(int a, int b) {
int i, j;
int x=a, y=b;
v[x][y] = 1;
int q[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
for(i=0; i<4; i++) {
x = a+q[i][0];
y = b+q[i][1];
if(x>=0 && x<h && y>=0 && y<w[x] && !v[x][y] && map[x][y] == ' ')
dfs(x, y);
}
}
int main() {
int n, i, j;
scanf("%d", &n);
getchar();
while(n--) {
h = 0;
memset(v, 0, sizeof(v));
while(gets(map[h])){
w[h]=strlen(map[h]);
if(strcmp(map[h],"_____")==0)break;
h++;
}
for(i=0; i<h; i++)
for(j=0; j<w[i]; j++) {
if(map[i][j] == '*' && v[i][j] == 0)
dfs(i, j);
}
for(int i=0;i<=h;i++){
for(int j=0;j<w[i];j++){
if(v[i][j]==1)cout<<"#";
else cout<<map[i][j];
}
cout<<endl;
}
}
return 0;
}