#include <bits/stdc++.h>
#define S 33
using namespace std;
string maze[S];
int len[S], n, m;
int xdir[] = {0, 1, 0, -1};
int ydir[] = {1, 0, -1, 0};
void dfs(int i, int j){
if(i < 0 || i >= m || j < 0 || j >= n || (maze[i][j] != ' ' && maze[i][j] != '*'))return;
if(maze[i][j] == '*' || maze[i][j] == 32)maze[i][j] = '#';
for(int z = 0; z < 4; z++){
int px = i+xdir[z];
int py = j+ydir[z];
dfs(px, py);
}
}
int main(){
int t;
cin >> t;
getchar();
while(t--){
int i = 0;
n = -1;
while(getline(cin, maze[i])){
len[i] = maze[i].size();
n = max(n, len[i]);
if(maze[i][0] == '_')break;
i++;
}
m = i;
int f = 0;
for(int k = 0; k < i; k++){
int nn = n-len[k];
while(nn--)maze[k].push_back('_');
}
for(int k = 0; k < i; k++)
for(int j = 0; j < n; j++)if(maze[k][j] == '*')dfs(k, j);
for(int k = 0; k < i; k++){
for(int j = 0; j < n; j++){
if(maze[k][j] == '_')break;
cout << maze[k][j];
}
puts("");
}
cout << maze[i] << endl;
}
return 0;
}
#define S 33
using namespace std;
string maze[S];
int len[S], n, m;
int xdir[] = {0, 1, 0, -1};
int ydir[] = {1, 0, -1, 0};
void dfs(int i, int j){
if(i < 0 || i >= m || j < 0 || j >= n || (maze[i][j] != ' ' && maze[i][j] != '*'))return;
if(maze[i][j] == '*' || maze[i][j] == 32)maze[i][j] = '#';
for(int z = 0; z < 4; z++){
int px = i+xdir[z];
int py = j+ydir[z];
dfs(px, py);
}
}
int main(){
int t;
cin >> t;
getchar();
while(t--){
int i = 0;
n = -1;
while(getline(cin, maze[i])){
len[i] = maze[i].size();
n = max(n, len[i]);
if(maze[i][0] == '_')break;
i++;
}
m = i;
int f = 0;
for(int k = 0; k < i; k++){
int nn = n-len[k];
while(nn--)maze[k].push_back('_');
}
for(int k = 0; k < i; k++)
for(int j = 0; j < n; j++)if(maze[k][j] == '*')dfs(k, j);
for(int k = 0; k < i; k++){
for(int j = 0; j < n; j++){
if(maze[k][j] == '_')break;
cout << maze[k][j];
}
puts("");
}
cout << maze[i] << endl;
}
return 0;
}
No comments:
Post a Comment