#K74232. Reverse Upper Triangle Pattern
Reverse Upper Triangle Pattern
Reverse Upper Triangle Pattern
You are given an integer n
. Your task is to draw a reverse upper triangle pattern inside a square grid of size n × n
. Each row of the grid must contain exactly two highlighted symbols ■
and the remaining positions must be filled with □
. The two ■
symbols are placed such that in the i-th
row (0-indexed) they occur at the i
-th column and the (n-1-i)
-th column. Note that when i
equals n-1-i
the symbol appears only once. All outputs should exactly match the pattern, including the newlines.
Example:
Input: 3</p>Output: ■□■ □■□ ■□■
Be sure to use LaTeX formatting for any mathematical expressions if needed. For instance, the positions of the highlighted symbols can be expressed by the formulas: $$i \quad \text{and} \quad n-1-i$$ for \(i = 0, 1, \ldots, n-1\).
inputFormat
The input consists of a single integer n
(n ≥ 1), representing the dimensions of the square grid.
Input is provided via standard input.
outputFormat
The output should be the generated pattern with exactly n
lines. Each line must consist of n
characters, where two positions in each line are highlighted with the symbol ■
and the rest are the symbol □
. Each line (except the last) should be terminated by a newline character. Output is produced on standard output.
3
■□■
□■□
■□■
</p>