diff options
Merge branch 'Angeld55:main' into sem03-solutions
7 files changed, 208 insertions, 4 deletions
| -rw-r--r-- | Sem. 03/README.md | 9 | ||||
| -rw-r--r-- | Sem. 03/drawing_examples.txt | 37 | ||||
| -rw-r--r-- | Sem. 03/solutions/exercise 08 - dollar pyramid.cpp | 19 | ||||
| -rw-r--r-- | Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp | 36 | ||||
| -rw-r--r-- | Sem. 03/solutions/exercise 10.cpp | 25 | ||||
| -rw-r--r-- | Sem. 03/solutions/exercise 11.cpp | 28 | ||||
| -rw-r--r-- | Sem. 03/solutions/exercise 15.cpp | 58 |
diff --git a/Sem. 03/README.md b/Sem. 03/README.md index 6fcb143..35624d4 100644 --- a/Sem. 03/README.md +++ b/Sem. 03/README.md @@ -67,11 +67,11 @@ do **Задача 2:** Да се напише програма, която приема 2 числа. Да се отпечатат всички общи делители сортиран наобратно. -*Вход: 28 21, Изход: 7 3 1* +*Вход: 28 21, Изход: 7 1* -*Вход: 60 30 Изход: 30 15 10 5 3 1* +*Вход: 60 30 Изход: 30 15 10 6 5 3 2 1* -*Вход: 5 4 3 0 Изход: 12* +*Вход: 19 17 Изход: 1* **Задача 3:** Да се напише програма, която приема число и премахва среднaта цифра , ако числото има нечетен брой цифри или премахва средните две цифри, ако числото има четен брой цифри. След това да се отпечата числото увеличено с 1-ца. @@ -112,6 +112,7 @@ do *Вход: 0 0 -1 5 -6 Изход: 2 3* +**!!** Задачите надолу са за рисуване на конзолата. Във файла *drawing_examples.txt* има изходите като текст.**!!** **Задача 8:** Да се напише програма, която приема цяло положително число n и отпечатва следната пирамида от доларчета @@ -159,5 +160,7 @@ do +**Задача 15:** Да се напише програма, която приема цяло положително число n и отпечатва следната папионка: + diff --git a/Sem. 03/drawing_examples.txt b/Sem. 03/drawing_examples.txt index 5179a0f..73e3130 100644 --- a/Sem. 03/drawing_examples.txt +++ b/Sem. 03/drawing_examples.txt @@ -63,7 +63,7 @@ $ $ $ $ задача 11:
-вход:9
+вход:3
1 2 3
6 5 4
7 8 9
@@ -120,6 +120,13 @@ $ $ $ $ . . . . .
. . . . . .
+вход: 5
+. . . . . . . . . .
+. . . .
+. . . . . . .
+. . . .
+. . . . . . . . . .
+
@@ -153,3 +160,31 @@ $ $ $ $ 1
121
1
+
+задача 15:
+
+вход: 3
+
+1 1
+1 2 2 1
+1 2 3 --- 3 2 1
+1 2 2 1
+1 1
+
+вход: 4
+1 1
+1 2 2 1
+1 2 3 3 2 1
+1 2 3 4 ---- 4 3 2 1
+1 2 3 3 2 1
+1 2 2 1
+1 1
+
+
+вход: 2
+
+1 1
+1 2 –- 2 1
+1 1
+
+
diff --git a/Sem. 03/solutions/exercise 08 - dollar pyramid.cpp b/Sem. 03/solutions/exercise 08 - dollar pyramid.cpp new file mode 100644 index 0000000..1ea164d --- /dev/null +++ b/Sem. 03/solutions/exercise 08 - dollar pyramid.cpp @@ -0,0 +1,19 @@ +#include <iostream> +using namespace std; + +int main() +{ + + int n; + cin >> n; + + for(int i = 1; i <= n; i++) + { + for(int j = 1; j <= i; j++) + cout << "$" << " "; // print as many dollars as the number of the current row + + cout << endl; + } + + return 0; +} diff --git a/Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp new file mode 100644 index 0000000..573b98b --- /dev/null +++ b/Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp @@ -0,0 +1,36 @@ +#include <iostream> +using namespace std; + +int main() +{ + + int n; + cin >> n; + + // print the first part of the pyramid (the one going from 1 to n(n-1)...21) + + for(int i = 1; i <= n; i++) + { + for(int k = n - i - 1; k >= 0; k--) + cout << " "; // print the spaces + + for(int j = i; j >= 1; j--) + cout << j; // print numbers j(j - 1)...21 + + cout << endl; + } + // print the second part of the pyramid (the one going from (n-1)...21 to 1 + + for(int i = n - 1; i >= 1; i--) + { + for(int k = n - i - 1; k >= 0; k--) + cout << " "; + + for(int j = i; j >= 1; j--) + cout << j; + + cout << endl; + } + + return 0; +} diff --git a/Sem. 03/solutions/exercise 10.cpp b/Sem. 03/solutions/exercise 10.cpp new file mode 100644 index 0000000..dae43ab --- /dev/null +++ b/Sem. 03/solutions/exercise 10.cpp @@ -0,0 +1,25 @@ +#include <iostream> + +using namespace std; + +int main() +{ + int count; + cin >> count; + + for (int i = 1; i <= count; i++) + { + for (int j = 0; j < count; j++) + { + if (j % 2 == 0) + { + cout << i + (count * j) << " "; + } + else + { + cout << (j + 1) * count - (i - 1) << " "; + } + } + cout << endl; + } +} diff --git a/Sem. 03/solutions/exercise 11.cpp b/Sem. 03/solutions/exercise 11.cpp new file mode 100644 index 0000000..66a90a9 --- /dev/null +++ b/Sem. 03/solutions/exercise 11.cpp @@ -0,0 +1,28 @@ +#include <iostream> + +using namespace std; + +int main() +{ + int count; + cin >> count; + + for (int i = 1; i <= count; i++) + { + if (i % 2 != 0) + { + for (int j = 1 + ((i - 1) * count); j <= i * count; j++) + { + cout << j << " "; + } + } + else + { + for (int j = i * count; j > (i - 1) * count; j--) + { + cout << j << " "; + } + } + cout << endl; + } +} diff --git a/Sem. 03/solutions/exercise 15.cpp b/Sem. 03/solutions/exercise 15.cpp new file mode 100644 index 0000000..652a201 --- /dev/null +++ b/Sem. 03/solutions/exercise 15.cpp @@ -0,0 +1,58 @@ +#include <iostream> +using namespace std; + +int main() +{ + int n; + cin >> n; + + int spacesCount = 2 * (n - 1) + n + 2 * (n - 1); + int toGuess; + for (int i = 1; i <= n - 1; i++) + { + for (int j = 1; j <= i; j++) + cout << j << " "; + + for (int j = 0; j < spacesCount; j++) + cout << " "; + + for (int j = i; j >= 1; j--) + cout << " " << j; + + spacesCount -= 4; + + cout << endl; + + } + + //mid + for (int i = 1; i <= n; i++) + cout << i << " "; + for (int i = 0; i < n; i++) + cout << '-'; + for (int i = n; i >= 1; i--) + cout << " " << i; + cout << endl; + + + //down + spacesCount += 4; + for (int i = n - 1; i >= 0; i--) + { + for (int j = 1; j <= i; j++) + cout << j << " "; + + for (int j = 0; j < spacesCount; j++) + cout << " "; + + for (int j = i; j >= 1; j--) + cout << " " << j; + + spacesCount += 4; + + cout << endl; + + } + + +} |
