Write a program that takes an integer n from the console and draws a warning sign STOP with size as in the examples below.
The input is an integer N within the range [3 … 1000].
Print on the console text lines, which depict the warning sign STOP, as in the examples.
We can see from the explanation that the input data will come from only one line which contains an integer within the range [3 … 1000]. Therefore, we will use a variable of
We can divide the figure into 3 parts – upper, middle and lower. The upper part contains two sub-parts – first row and rows in which the sign widens. The first row is made of a beginning
., middle part
_ and an end
.. After looking at the examples we can say that the beginning is
n + 1 columns wide, so it is good to write this value in a separate variable.
We must also create a second variable, in which we will keep the value of the middle of the first row, which has a size of
2 * n + 1.
After we have declared and initialized the two variables, we can print the first row on the console.
In order to draw the rows in which the sign is getting "wider", we need to create a loop, which runs
n times. The structure of a row contains a beginning
// + middle part
\\ and an end
.. In order to reuse the already created variables, we need to decrease
dots by 1 and
underscores by 2, because we have already printed the first row, and the dots and underscores in the upper part of the figure are decreasing.
In each following iteration the beginning and the end decrease by 1, and the middle part increases by 2.
The middle part of the figure begins with
_, middle part
STOP! and an end
\\. The count of the underscores
(underscores - 5) / 2.
The lower part of the figure, in which the width of the sign decreases, can be done by creating another loop, which runs
n times. The structure of a row is – a beginning
\\, middle part
_ and an end
.. The number of the dots in the first iteration should be 0 and in each following one it increases by one. Therefore, we can say that the size of the dots in the lower part of the figure equals
In order for our program to work properly, in each iteration of the loop we need to decrease the number of
_ by 2.
Test your solution here: https://judge.softuni.org/Contests/Practice/Index/513#2.