Write a program that takes an integer n from the console and draws a butterfly 2 * n - 1 columns wide and 2 * (n - 2) + 1 rows tall, as in the examples below. The left and right parts are n - 1 wide.
The input is an integer n within the range [3 … 1000].
Print on the console 2 * (n - 2) + 1 text rows, depicting the butterfly as in the examples.
We can see in the explanation that the input data will be taken from only one row which contains an integer within the range [3 … 1000]. This is why we will use a variable of
We can divide the figure into 3 parts – upper wing, body and lower wing. In order to draw the upper wing, we need to divide it into parts – beginning
*, middle part
\ / and end
*. After looking at the examples we find out that the beginning is with size
n - 2.
We can also see that the upper wing is with size
n - 2, and that's why we can make a loop which repeats
We can see in the examples that on an even row we have a beginning
*, a middle part
\ / and an end
*, and on an odd row – beginning
-, middle part
\ / and an end
-. This is why we must add an
if-else condition to check if the row is even or odd and then to draw one of the two types of rows.
In order to create the body of the butterfly we can use the variable
halfRowSize again and print on the console exactly one row. The body structure begins with
(white space), middle
@ and ends with
Now we need to print the lower wing, which is the same as the upper one.
Test your solution here: https://judge.softuni.org/Contests/Practice/Index/513#1.