#C6688. Diamond Pattern Generator

    ID: 50475 Type: Default 1000ms 256MiB

Diamond Pattern Generator

Diamond Pattern Generator

Given an odd integer nn, write a program that generates a diamond pattern inside a square grid of size n×nn \times n. The diamond is composed of the character * and is centered both vertically and horizontally in the grid.

The number of * characters in each row is determined as follows:

  • For the upper half (including the middle row), if ii is the zero-based index of the row (with 0in120 \leq i \leq \frac{n-1}{2}), then the number of stars is given by   2i+1  \;2i+1\;.
  • For the lower half, the number of stars is given by   2(ni1)+1  \;2(n-i-1)+1\;.

All remaining positions in the row should be filled with a whitespace character. Your program should read the input from stdin and print the resulting diamond pattern to stdout, with each row on a new line.

inputFormat

The input consists of a single line containing an odd integer nn (n1)(n \geq 1) which represents the size of the grid.

outputFormat

Output the diamond pattern composed of * characters. The diamond should be centered in an n×nn \times n grid. Each row of the grid must be printed on a new line.## sample

1
*

</p>