https://www.luogu.org/problemnew/show/P1101
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N=100+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
char str[N][N];
char vis[N][N];
char s[10]="yizhong";
int a[][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
bool dfs(int x,int y,int c,int k){
if(c==7){
return 1;
}else{
int tx=x+a[k][0];
int ty=y+a[k][1];
if(0<=tx&&tx<n&&0<=ty&&ty<n&&str[tx][ty]==s[c]){
if(dfs(tx,ty,c+1,k)){
vis[tx][ty]=1;
return 1;
}
}
}
return 0;
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
scanf("%d",&n);
for(int i = 0; i < n; i++) cin >> str[i];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(str[i][j]=='y'){
for(int k=0;k<8;k++){
int tx=i+a[k][0];
int ty=j+a[k][1];
if(0<=tx&&tx<n&&0<=ty&&ty<n&&str[tx][ty]=='i'){
if(dfs(tx,ty,2,k)){
vis[i][j]=1;
vis[tx][ty]=1;
}
}
}
}
}
}
for(int i=0;i<n;i++){//输出结果
for(int j=0;j<n;j++)
if(vis[i][j]) printf("%c",str[i][j]);
else printf("*");
printf("\n");
}
//cout << "Hello world!" << endl;
return 0;
}