From 5294e73a21f3402e14fcf3379c721275e2dd19c2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 23 Nov 2025 15:25:29 +0200 Subject: feat(Week08): Add solutions --- Week08/Exercise01.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Week08/Exercise01.cpp (limited to 'Week08/Exercise01.cpp') diff --git a/Week08/Exercise01.cpp b/Week08/Exercise01.cpp new file mode 100644 index 0000000..3052799 --- /dev/null +++ b/Week08/Exercise01.cpp @@ -0,0 +1,29 @@ +#include + +/* Тази задача може да се реши без матрици. + * Все пак идеята е да упражним точно тях. + */ + +int main() { + const unsigned int SIZE = 5; + int mat[SIZE][SIZE]; + + for (unsigned int i = 0; i < SIZE; i++) + for (unsigned int j = 0; j < SIZE; j++) + std::cin >> mat[i][j]; + + unsigned int countZeroes = 0; + for (unsigned int i = 0; i < SIZE; i++) + for (unsigned int j = 0; j < SIZE; j++) + countZeroes += mat[i][j] == 0; + + /* Бройката нули е повече от бройката на всички елементи които не са нули. + * Алтернативно, може и да се пази втори брояч за ненулеви елементи. + */ + if (countZeroes > SIZE * SIZE - countZeroes) + std::cout << "Sparse" << std::endl; + else + std::cout << "Not sparse" << std::endl; + + return 0; +} -- cgit v1.3.1-23-gd82d