#B4306. Diamond Matrix Painting
Diamond Matrix Painting
Diamond Matrix Painting
Given an odd integer \(n\) and an uppercase letter \(Center\), generate a \(n \times n\) character matrix. The matrix is composed of uppercase letters and periods ('.'). The uppercase letters form a diamond shape. In the diamond, the bottom letter (at the center of the diamond) is the given \(Center\), and the other letters are determined by decrementing from \(Center\). Specifically, define \(L = \frac{n-1}{2}\) and let \(p[i]=Center - L + i\) for \(0 \le i \le L\). Then the full diamond row (the middle row) is constructed as:
[ p = [p[0], p[1], \ldots, p[L], p[L-1], \ldots, p[0]] ]
For each row \(r\) (with \(0 \le r < n\)), let \(d = |r - L|\) and let \(k = L - d\). The row’s diamond part is constructed as follows:
[ row = [p[0], p[1], \ldots, p[k], p[k-1], \ldots, p[0]] ]
This diamond part is then centered by padding both sides with \(L - k\) periods. For example:
- When \(n=3\) and \(Center=C\):
\(L=1, p = [B, C]\), full diamond row becomesBCB
, and the output is:
.B. BCB .B.
- When \(n=5\) and \(Center=Z\):
\(L=2, p = [X, Y, Z]\), full diamond row becomesXYZYX
, and the output is:
..X.. .XYX. XYZYX .XYX. ..X..
inputFormat
The input consists of a single line containing an odd integer n
(\(3 \leq n \leq 99\)) and an uppercase letter Center
, separated by a space.
outputFormat
Output the generated \(n \times n\) matrix. Each of the \(n\) lines should contain exactly \(n\) characters.
sample
3 C
.B.
BCB
.B.
</p>