Spirals P44243


Statement
 

pdf   zip

html

Write a program that prints “spirals” of size n × n, as it is shown in the examples.

Input

Input consists of a sequence of strictly positive natural numbers, ended with zero.

Output

For each n, print a spiral of size n × n. Note that in the bottom row and in the right column there are only ‘X’s. Print an empty line after each spiral.

Observation

A matrix is not needed to solve this problem, but use it for simplicity.

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++