Problem: Axe

Write a program that takes an integer n and draws an axe with size as shown below. The width of the axe is 5 * N columns.

Input Data

The input is an integer n within the range [2...42].

Output Data

Print an axe on the console just as shown in the examples.

Sample Input and Output

Input Output Input Output
2 ------**--
------*-*-
*******-*-
------***-
5 ---------------**--------
---------------*-*-------
---------------*--*------
---------------*---*-----
---------------*----*----
****************----*----
****************----*----
---------------*----*----
--------------********---
Input Output
8 ------------------------**--------------
------------------------*-*-------------
------------------------*--*------------
------------------------*---*-----------
------------------------*----*----------
------------------------*-----*---------
------------------------*------*--------
------------------------*-------*-------
*************************-------*-------
*************************-------*-------
*************************-------*-------
*************************-------*-------
------------------------*-------*-------
-----------------------*---------*------
----------------------*-----------*-----
---------------------***************----

Hints and Guidelines

In order to solve the problem, we first need to calculate the dashes in the left, the middle dashes, the dashes in the right and the whole length of the figure.

After we have declared and initialized the variables, we can begin drawing the figure by starting with the upper part. We can see from the examples what the structure of the first row is, and we can create a loop, which runs n times. At each iteration of the loop the middle dashes increase by 1, and the right dashes decrease by 1.

In order to use again the variables that we created in order to draw the handle of the axe, we need to decrease the middle dashes by 1, and we need to increase the left dashes by 1.

Printing the Handle

We can draw the handle of the axe by creating a loop, which runs n - 2 times. We can see in the examples what its structure is.

Printing the Lower Part of the Axe

We need to divide the lower part of the figure into two sub-parts – head of the axe and the last row of the figure. We will print the head of the axe on the console by creating a loop that runs n / 2 - 1 times. At each iteration the left dashes and the right dashes decrease by 1, and the middle dashes increase by 2.

For the last row of the figure we can use the three declared and initialized variables leftDashes, middleDashes, rightDashes again.

Testing in the Judge System

Test your solution here: https://judge.softuni.org/Contests/Practice/Index/513#4.

results matching ""

    No results matching ""