Problem: "Stop" Sign

Write a program that takes an integer n from the console and draws a warning sign STOP with size as in the examples below.

Input Data

The input is an integer N within the range [3 … 1000].

Output Data

Print on the console text lines, which depict the warning sign STOP, as in the examples.

Sample Input and Output

Input Output Input Output
3 ...._______....
...//_____\\...
..//_______\\..
.//_________\\.
//___STOP!___\\
\\___________//
.\\_________//.
..\\_______//..
6 ......._____________.......
......//___________\\......
.....//_____________\\.....
....//_______________\\....
...//_________________\\...
..//___________________\\..
.//_____________________\\.
//_________STOP!_________\\
\\_______________________//
.\\_____________________//.
..\\___________________//..
...\\_________________//...
....\\_______________//....
.....\\\___________//.....
Input Output
7 ........_______________........
.......//_____________\\.......
......//_______________\\......
.....//_________________\\.....
....//___________________\\....
...//_____________________\\...
..//_______________________\\..
.//_________________________\\.
//___________STOP!___________\\
\\___________________________//
.\\_________________________//.
..\\_______________________//..
...\\_____________________//...
....\\___________________//....
.....\\_________________//.....
......\\_______________//......

Hints and Guidelines

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 int type.

Divide the Figure into Parts

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.

Printing the Upper Part of the Sign

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.

Printing the Middle Row and the Lower Part of the Sign

The middle part of the figure begins with // + _, middle part STOP! and an end _ + \\. The count of the underscores _ is (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 i.

In order for our program to work properly, in each iteration of the loop we need to decrease the number of _ by 2.

Testing in the Judge System

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

results matching ""

    No results matching ""