Spirals P59112


Statement
 

pdf   zip

Spirals

Your task is to write a program that prints “spirals” of size n×nn \times n, as it is shown in the examples.

Input

The input consists of a sequence of natural numbers ended with zero.

Output

For each nn, your program must print a spiral of size n×nn \times n. Notice that in the row of the bottom and the column on the rigth there only are |’X’|s. Print a line in white after each spiral.

Observation

Although it is not essential use a matrix to solve this problem, do it for simplicity.

Author

Salvador Roura (en: Carlos Molina)

© Jutge.org, 2006–2025.

Public test cases
  • Input

    4
    6
    7
    0
    

    Output

    .XXX
    .X.X
    ...X
    XXXX
    
    .XXXXX
    .X...X
    .X.X.X
    .XXX.X
    .....X
    XXXXXX
    
    .XXXXXX
    .X....X
    .X.XX.X
    .X..X.X
    .XXXX.X
    ......X
    XXXXXXX
    
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python