#B4226. Decrypted Password
Decrypted Password
Decrypted Password
Given an n×n matrix of characters representing an initial encrypted password, your task is to obtain the final form of the password by performing two transformations.
- Snake Reading: Starting at the top-left element of the matrix, move one step to the right. Then, traverse diagonally down‐left until a boundary is reached. Next, take one step along the boundary (either downward or to the right, whichever is valid) and then traverse diagonally up‐right until hitting a boundary. Continue alternating these two phases until you arrive at the bottom-right element. This process produces an intermediate string S of length n×n.
The movement can be summarized as follows:
\(\begin{cases} \text{Start at }(0,0)\\ \text{Step 1: Move right to }(0,1)\\ \text{Then, while possible, move diagonally down-left.}\\ \text{Make one boundary step (down if possible; otherwise, right),}\\ \text{then while possible, move diagonally up-right.}\\ \text{Repeat until reaching }(n-1, n-1). \end{cases}\) - Spiral Filling: Fill a new n×n matrix using the characters of S in spiral order. Start at the top-left corner and fill the top row from left to right, then the rightmost column from top to bottom, then the bottom row from right to left, and finally the leftmost column from bottom to top. Continue this process inward until the entire matrix is filled.
The final form of the password is the matrix obtained in the second step. Print the matrix by outputting each row on a new line.
inputFormat
The first line contains an integer n (1 ≤ n ≤ 100), the size of the matrix. The following n lines each contain a string of exactly n characters representing one row of the matrix.
outputFormat
Output the final form of the password as an n×n matrix. Each of the n lines should contain exactly n characters, corresponding to one row of the final matrix.
sample
1
A
A
</p>