diff options
| -rw-r--r-- | week06/ex1.cpp | 41 | ||||
| -rw-r--r-- | week06/ex2.cpp | 28 | ||||
| -rw-r--r-- | week06/ex3.cpp | 50 | ||||
| -rw-r--r-- | week06/ex4.cpp | 15 |
4 files changed, 134 insertions, 0 deletions
diff --git a/week06/ex1.cpp b/week06/ex1.cpp new file mode 100644 index 0000000..36938b7 --- /dev/null +++ b/week06/ex1.cpp @@ -0,0 +1,41 @@ +#include <iostream> + +int main() { + // Вход + size_t N, M; + std::cin >> N >> M; + + int matrix1[60][60], matrix2[60][60]; + /* При matrix1[i][j] няма значение дали i се води ред или стълб, важното е да + * изберете едно значение и то да си стои до края на задачата. + */ + for (size_t row = 0; row < N; row++) { + for (size_t col = 0; col < M; col++) { + std::cin >> matrix1[row][col]; + } + } + + for (size_t row = 0; row < M; row++) { + for (size_t col = 0; col < N; col++) { + std::cin >> matrix2[row][col]; + } + } + + // Умножение + int multMatrix[60][60] = { { 0 } }; + for (size_t row = 0; row < N; row++) { + for (size_t col = 0; col < N; col++) { + for (size_t i = 0; i < 60; i++) { + multMatrix[row][col] += matrix1[row][i] * matrix2[i][col]; + } + } + } + + // Изход + for (size_t row = 0; row < N; row++) { + for (size_t col = 0; col < N; col++) { + std::cout << multMatrix[row][col] << " "; + } + std::cout << std::endl; + } +} diff --git a/week06/ex2.cpp b/week06/ex2.cpp new file mode 100644 index 0000000..1c217bf --- /dev/null +++ b/week06/ex2.cpp @@ -0,0 +1,28 @@ +#include <iostream> + +int main() { + size_t N; + std::cin >> N; + + unsigned nums[30]; + for (size_t i = 0; i < N; i++) { + std::cin >> nums[i]; + } + + bool lastWas = false; + unsigned count = 0; + + bool hasGE = true; + for (unsigned comp = 1; hasGE; comp++) { + hasGE = false; + for (size_t i = 0; i < N; i++) { + if ((nums[i] >= comp) != lastWas) { + if (!lastWas) count++; + lastWas = !lastWas; + hasGE = true; + } + } + } + + std::cout << count << std::endl; +} diff --git a/week06/ex3.cpp b/week06/ex3.cpp new file mode 100644 index 0000000..a37bbb0 --- /dev/null +++ b/week06/ex3.cpp @@ -0,0 +1,50 @@ +#include <iostream> + +void putOn(char board[3][3], char marker, size_t position) { + position--; + board[position / 3][position % 3] = marker; +} + +void print(char board[3][3]) { + for (size_t row = 0; row < 3; row++) { + for (size_t col = 0; col < 3; col++) { + std::cout << board[row][col]; + } + std::cout << std::endl; + } +} + +unsigned win(char board[3][3]) { + bool notFull = false; + char start = ' '; + bool won = false; + + /* Проверяваме редовете */ + for (size_t row = 0; row < 3; row++) { + start = board[row][0]; + + } +} + + + +int main() { + char board[3][3] = { { ' ' } }; + bool playerOneTurn = true; + + size_t position; + unsigned winStatus = 0; + do { + std::cin >> position; + if (playerOneTurn) { + putOn(board, 'X', position); + } + else { + putOn(board, 'O', position); + } + playerOneTurn = !playerOneTurn; + + print(board); + winStatus = win(board); + } while (winStatus == 0); +} diff --git a/week06/ex4.cpp b/week06/ex4.cpp new file mode 100644 index 0000000..b500b33 --- /dev/null +++ b/week06/ex4.cpp @@ -0,0 +1,15 @@ +#include <iostream> + +int main() { + char chocolate[41][41] = { { '#' } }; + size_t N, M; + std::cin >> N >> M; + + bool firstPlayerTurn = false; + size_t row, col; + unsigned winStatus = 0; + do { + firstPlayerTurn = !firstPlayerTurn; + winStatus = chomp(chocolate, row, col); + } while(winStatus == 0); +} |
