#P1101. Highlight Yizhong in a Letter Matrix
Highlight Yizhong in a Letter Matrix
Highlight Yizhong in a Letter Matrix
Given an \( n \times n \) letter matrix, there may be multiple occurrences of the word yizhong hidden in it. Each occurrence is formed by consecutive letters in one of the eight possible directions without changing direction once started. Occurrences may cross over, so letters can be shared among words. Your task is to output the matrix such that only the letters that are part of some occurrence of yizhong are displayed, and all other letters are replaced with an asterisk (*
).
The word to search is given by the LaTeX formatted sequence: \( yizhong \).
inputFormat
The input begins with a line containing a single integer \( n \) (\( n \ge 7 \)). Following this are \( n \) lines, each containing a string of exactly \( n \) characters representing a row of the matrix.
outputFormat
Output \( n \) lines. In the output matrix, if a character is part of any occurrence of the word yizhong, print the character; otherwise, print an asterisk (*
).
sample
7
yizhong
abcdefg
hijklmn
opqrstu
vwxyzab
cdefghi
jklmnop
yizhong
*******
</p>