eolymp
bolt
Try our new interface for solving problems
Problems

Prettify Text Blocks

Prettify Text Blocks

You are given a rectangular text block, consisting of periods "\textbf{.}" and asterisks "\textbf{*}". Two horizontally or vertically adjacent asterisks are \textbf{connected}. You task is to convert each asterisk to a different character, depending on how it connects to other asterisks. An asterisk is converted to: \begin{itemize} \item "\textbf{o}" (the lower case letter o) if it is not connected, \item "\textbf{-}" if it is only connected horizontally (left/right/left and right), \item "\textbf{|}" if it is only connected vertically (up/down/up and down), \item "\textbf{+}" otherwise. \end{itemize} \InputFile The first input line contains the number of test cases \textbf{N}, \textbf{1} ≤ \textbf{N} ≤ \textbf{50}. Each test case begins with a line containing integers \textbf{h} and\textit{ }\textbf{w}, separated by space. \textbf{h} lines follow. Each line \textbf{i}, \textbf{1} ≤ \textbf{i} ≤ \textbf{h}, consists of a string \textbf{s}. The input text block is represented by vertically stacking \textbf{s_1}, \textbf{s_2}, ..., \textbf{s_h}. \begin{itemize} \item \textbf{h} is the height of the text block, and satisfies \textbf{1} ≤ \textbf{h} ≤ \textbf{50}. \item \textbf{w} is the width of the text block, and satisfies \textbf{1} ≤ \textbf{w} ≤ \textbf{50}. \item For each \textbf{i}, \textbf{1} ≤ \textbf{i} ≤ \textbf{h}, \textbf{s_i} is a \textbf{length-}\textit{\textbf{w}} string of periods "\textbf{.}" or asterisks "\textbf{*}". \end{itemize} \OutputFile For each test case, print \textbf{h} lines of length-\textit{w} strings, represents the converted text block. Print a blank line between test cases, but not after the last test case.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
4 5
*****
*...*
*...*
*****
7 7
*******
.*.*.*.
.****..
*....**
...*...
**.*.**
**.*..*
Output example #1
+---+
|...|
|...|
+---+

-+-+-+-
.|.|.|.
.+-+-..
o....--
...|...
++.|.-+
++.|..|
Source University of Toronto 2010 ACM Tryout: Saturday, October 2, 2010