diff options
new
4 files changed, 0 insertions, 116 deletions
| -rw-r--r-- | Sem. 08/README.md | 7 | ||||
| -rw-r--r-- | Sem. 08/task1.cpp | 17 | ||||
| -rw-r--r-- | Sem. 08/task2.cpp | 43 | ||||
| -rw-r--r-- | Sem. 08/task3.cpp | 49 |
diff --git a/Sem. 08/README.md b/Sem. 08/README.md deleted file mode 100644 index 367f048..0000000 --- a/Sem. 08/README.md +++ /dev/null @@ -1,7 +0,0 @@ -**Задача 1:** Да се реализира функция, която приема булев масив и връща числото, което е репрезентирано в него(в двоична бройна система). - -**Задача 2:** Да се реализира функция, която приема масив, в който всеки елемент се среща 2 пъти, с изключение на един елемент, който се среща точно веднъж. -Функцията да връща кой е този елемент. - - -**Задача 3:** Напишете функция, която приема масив връща дължината на най-дългият подмасив, който е палиндром. diff --git a/Sem. 08/task1.cpp b/Sem. 08/task1.cpp deleted file mode 100644 index b8c5943..0000000 --- a/Sem. 08/task1.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include <iostream> -using namespace std; - -const int SIZE = 32; - -int convert(bool arr[SIZE]) -{ - int result = 0; - for (int i = 31; i >= 0; i--) - result += arr[i] * (1 << 31-i); - return result; -} -int main() -{ - bool arr[SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1 }; - cout << convert(arr); -} diff --git a/Sem. 08/task2.cpp b/Sem. 08/task2.cpp deleted file mode 100644 index ecc9d74..0000000 --- a/Sem. 08/task2.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include <iostream> -using namespace std; - -const int SIZE = 30; -int countOccurrences(int arr[SIZE], int n, int el) -{ - int count = 0; - for (int i = 0; i < n; i++) - { - if (arr[i] == el) - count++; - } - return count; -} - -int getLonlyNumber(int arr[SIZE], int n) -{ - for (int i = 0; i < n; i++) - { - if (countOccurrences(arr, n, arr[i]) == 1) - return arr[i]; - } - return -1; - -} - -int getLonlyNumberBetter(int arr[SIZE], int n) -{ - int res = 0; - for (int i = 0; i < n; i++) - res ^= arr[i]; - return res; -} - -int main() -{ - int arr[SIZE]; - int n; - cin >> n; - for (int i = 0; i < n; i++) - cin >> arr[i]; - cout << getLonlyNumberBetter(arr, n); -} diff --git a/Sem. 08/task3.cpp b/Sem. 08/task3.cpp deleted file mode 100644 index a6b0ca9..0000000 --- a/Sem. 08/task3.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include <iostream> -using namespace std; - -const int SIZE = 30; -bool isSubarrayPalindrome(int arr[SIZE], int startIndex, int endIndex) -{ - while (startIndex < endIndex) - { - if (arr[startIndex] != arr[endIndex]) - return false; - startIndex++; - endIndex--; - } - return true; -} -void print(int arr[SIZE]) -{ - for (int i = 0; i < SIZE; i++) - cout << arr[i]; - cout << endl; -} - -int longestPalindromicSubarray(int arr[SIZE], int n) -{ - int currentSize = n; - - int startIndex = 0; - int endIndex = startIndex + currentSize-1; - while (true) - { - if (isSubarrayPalindrome(arr, startIndex, endIndex)) - return endIndex - startIndex + 1; - startIndex++; - endIndex++; - if (endIndex == n)//last iteration - { - currentSize--; - startIndex = 0; - endIndex = startIndex + currentSize - 1; - } - } -} -int main() -{ - - int arr[SIZE] = {1,4,3,2,3}; - cout << longestPalindromicSubarray(arr, 5); - -} |
