From 55fc7eb3bba83f4084b2f897c61d0280a5f9c097 Mon Sep 17 00:00:00 2001 From: angeld55 Date: Sat, 2 Oct 2021 17:44:35 +0300 Subject: new --- Sem. 08/task3.cpp | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 Sem. 08/task3.cpp (limited to 'Sem. 08/task3.cpp') 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 -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); - -} -- cgit v1.3.1-23-gd82d