You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Content/Chapter-6-2-nested-loops-exam-problems/exam-problems/arrow/arrow.md
+4-2
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,8 @@ Print a vertical arrow on the console, in which "**`#`**" (number sign) marks th
25
25
From the explanation we see that **the input data** will be read from one input line only, which will contain **an integer** within the range [**3 … 1000**]. This is why we will use **a variable** of **`int`** type.
26
26
27
27

28
+
29
+
### Divide the Figure into Parts
28
30
29
31
We can divide the figure into **3 parts** – upper, middle and lower one. **The upper part** contains two sub-parts – a first row and a body of the arrow. We can see from the examples that the count of **the outer dots** on the first row and in the body of the arrow is **`(n - 1) / 2`**. We can write this value in **a variable****`outerDots`**.
30
32
@@ -38,7 +40,7 @@ We can see from the examples the structure of the first row. We must use the dec
38
40
39
41

40
42
41
-
## Printing the Body and the Middle Row of the Arrow
43
+
###Printing the Body and the Middle Row of the Arrow
42
44
43
45
In order to draw **the body of the arrow**, we need to create **a loop**, which runs **`n - 2`** times.
44
46
@@ -48,7 +50,7 @@ In order to draw **the body of the arrow**, we need to create **a loop**, which
48
50
49
51

50
52
51
-
## Printing the Lower Part of the Arrow
53
+
###Printing the Lower Part of the Arrow
52
54
53
55
In order to draw **the lower part of the arrow**, we need to assign new values to **the variables****`outerDots`** and **`innerDots`**.
Copy file name to clipboardExpand all lines: Content/Chapter-6-2-nested-loops-exam-problems/exam-problems/axe/axe.md
+6-2
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,10 @@ In order to solve the problem, we first need to calculate **the dashes in the le
26
26
27
27

28
28
29
+
### Divide the Figure into Parts
30
+
31
+
We divide the figure into 3 parts: upper part, middle part (the handle), down part.
32
+
29
33
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.
30
34
31
35

@@ -34,13 +38,13 @@ In order to use again **the variables** that we created in order to draw the han
34
38
35
39

36
40
37
-
## Printing the Handle
41
+
###Printing the Handle
38
42
39
43
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.
40
44
41
45

42
46
43
-
## Printing the Lower Part of the Axe
47
+
###Printing the Lower Part of the Axe
44
48
45
49
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.
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`**.
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 **`(white space)`**.
Let’s solve the problem step by step: read the input, perform some calculations, print the fort roof, print the fort body, print the fort base.
26
+
27
+
### Reading the Input Data
24
28
25
29
We can see from the explanation that **the input data** will be only one line which will contain **an integer** within the range [**3 … 1000**]. Therefore, we will use **a variable** of **`int`** type.
26
30
@@ -31,7 +35,7 @@ After we have declared and initialized the input data, we must divide **the fort
31
35
* body
32
36
* base
33
37
34
-
## Calculating and Printing the Roof
38
+
###Calculating and Printing the Roof
35
39
36
40
We can see from the examples that **the roof** is made of **two towers** and **a middle part**. Each tower has a beginning **`/`**, middle part **`^`** and an end **`\`**.
37
41
@@ -51,13 +55,13 @@ In order to print **the roof**, we will use **`new string`**, which takes two pa
**The body of the fort** contains a beginning **`|`**, a middle part **`(white space)`** and an end **`|`**. **The middle part** is a blank space with size of **`2 * n - 2`**. The number of **the rows** used for walls can be found in the given parameters: **`n - 3`**. This code prints the body of the fort:
In order to draw the last but one row, which is a part of the base, we need to print a beginning **`|`**, middle part **`(white space)_(white space)`** and an end **`|`**. In order to do this, we can use the already declared variables **`colSize`** and **`midSize`** again, because we can see from the examples that they are equal to the **`_`** in the roof.
Copy file name to clipboardExpand all lines: Content/Chapter-6-2-nested-loops-exam-problems/exam-problems/stop/stop.md
+4-2
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,8 @@ We can see from the explanation that **the input data** will come from only one
26
26
27
27

28
28
29
+
### Divide the Figure into Parts
30
+
29
31
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**.
30
32
31
33

@@ -38,7 +40,7 @@ After we have declared and initialized the two variables, we can print the first
38
40
39
41

40
42
41
-
## Printing the Upper Part of the Sign
43
+
###Printing the Upper Part of the Sign
42
44
43
45
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**.
44
46
@@ -48,7 +50,7 @@ In each following iteration **the beginning** and **the end** decrease by 1, and
48
50
49
51

50
52
51
-
## Printing the Middle Row and the Lower Part of the Sign
53
+
###Printing the Middle Row and the Lower Part of the Sign
52
54
53
55
**The middle part** of the figure begins with **`//`** + **`_`**, middle part **`STOP!`** and an end **`_`** + **`\\`**. The count of the underscores **`_`** is **`(underscores - 5) / 2`**.
Let's declare and initialize the **variables** that will store the **characters** of the password: for the characters of **digit** type – **`int`** – **`d1`**, **`d2`**, **`d3`**, and for the **letters** – of **`char`** type – **`l1`**, **`l2`**. To make it easier we will skip explicit specification of the type by replacing it with the keyword **`var`**.
43
43
44
-
## Processing the Input Data and Printing Output
44
+
###Processing the Input Data and Printing Output
45
45
46
46
We need to create **five****`for`** nested loops, one for each variable. To ensure that the last digit **d3** is **greater** than the first two, we will use the built-in function **`Math.Max (...)`**.
0 commit comments