#C6402. Diamond Pattern Generator

    ID: 50159 Type: Default 1000ms 256MiB

Diamond Pattern Generator

Diamond Pattern Generator

Given a positive odd integer \(n\) (i.e. \(n \ge 1\) and \(n \bmod 2 = 1\)), output a diamond-shaped pattern made up of asterisks (*). The pattern should be centered such that its widest part has exactly \(n\) asterisks. If the input does not satisfy the conditions, the program should output nothing.

Example:

Input: 5

Output: *




The diamond is constructed by increasing the number of asterisks by 2 on each line until the middle line and then decreasing symmetrically. Formally, for a valid \(n\), the \(i^{th}\) line (with \(0 \le i < n\)) contains:

  • If \(i \leq \frac{n-1}{2}\): \(2 \times i + 1\) asterisks
  • If \(i > \frac{n-1}{2}\): \(2 \times (n-i) - 1\) asterisks

The asterisks on each line must be preceded by a number of spaces so that the line is centered with respect to the widest line.

inputFormat

The input consists of a single line from standard input containing one integer \(n\).

outputFormat

If \(n\) is a positive odd integer, output the diamond-shaped pattern exactly as described. Otherwise, output an empty string.

## sample
5
  *



*

</p>