#P1101. 单词方阵

单词方阵

Description

Given an n×nn \times n letter grid, there may be multiple occurrences of the word yizhong. Each word is placed contiguously along a single direction. Placement can be along any of the 88 directions, and the direction does not change within the same word. Different words may cross and share letters. In the output, replace letters that are not part of any occurrence of the word with * to highlight the words.

Input Format

  • The first line contains an integer nn (7n1007 \le n \le 100).
  • Starting from the second line, input the n×nn \times n letter matrix.

Output Format

Output the n×nn \times n matrix where letters not belonging to any yizhong are replaced by *.

7
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa

*******
*******
*******
*******
*******
*******
*******

8
qyizhong
gydthkjy
nwidghji
orbzsfgz
hhgrhwth
zzzzzozo
iwdfrgng
yyyygggg
*yizhong
gy******
n*i*****
o**z****
h***h***
z****o**
i*****n*
y******g

Hint

Translated by ChatGPT 5