思路:
题目很好理解,输出一个地图。’X‘代表墙,如果有*的地方,就往四面八方扩散,能到的地方就变成’#‘。
题意:直接搜索地图,走过的点变成’#‘即可
#include <stdio.h>
#include <string.h>
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
char mp[40][85];
int a,b;
int tot;
int find(){
for (int i = 0;i < tot;i++){
int len = strlen(mp[i]);
for (int j = 0;j < len;j++){
if (mp[i][j] == '*'){
mp[i][j] = '#';
a = i;
b = j;
return true;
}
}
}
return false;
}
void dfs(int a,int b){
for (int i = 0;i < 4;i++){
int x = a + dx[i];
int y = b + dy[i];
if (x < 0 || x >= tot || y < 0 || y >= strlen(mp[0])) continue;
if (mp[a + dx[i]][b + dy[i]] == ' '){
mp[a + dx[i]][b + dy[i]] = '#';
dfs(a + dx[i],b + dy[i]);
}
}
}
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int t;
scanf("%d",&t);
getchar();
while(t--){
memset(mp,0,sizeof mp);
tot = 0;
while(gets(mp[tot]) != NULL){
if (mp[tot][0] == '_'){
tot++;
break;
}
tot++;
}
while(find()){
dfs(a,b);
}
for (int i = 0;i < tot;i++)
puts(mp[i]);
}
return 0;
}