#C4278. Spiral Matrix Order
Spiral Matrix Order
Spiral Matrix Order
Given a positive integer N, construct an N×N spiral matrix filled with the integers from $1$ to $N^2$ in clockwise order. The matrix should be represented as a single string where each row's numbers are separated by a single space and each row ends with a literal ' $' (a space followed by a dollar sign).
For example, when N = 3 the expected output is:
1 2 3 $8 9 4 $7 6 5 $
Your task is to implement a solution that reads N from standard input and writes the spiral order string to standard output following the pattern described.
inputFormat
The input is provided via standard input. It consists of a single integer N on one line, where N is the size of the square spiral matrix.
outputFormat
Output a single line to standard output: the spiral order representation of the matrix. Each row's numbers must be separated by a space and terminated with ' $' (a space and a dollar sign) as shown in the examples.
## sample1
1 $