MaksNew

Untitled

Jan 30th, 2021
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. void searchForPalindrom(int* arr, int size, int& watch)
  2. {
  3.     int bufi = 0, bufj = 0, j = 0;
  4.     bool isPalindrom = true;
  5.     for (int i = 0; i < size; ++i)
  6.     {
  7.         j = size - 1;
  8.         if (arr[i] == arr[j])
  9.         {
  10.             bufi = i;
  11.             bufj = j;
  12.             isPalindrom = true;
  13.             while (bufi != bufj && isPalindrom)
  14.             {
  15.                 if (arr[bufi] != arr[bufj])
  16.                 {
  17.                     isPalindrom = false;
  18.                 }
  19.                 ++bufi;
  20.                 --bufj;
  21.             }
  22.             if (isPalindrom && i != j)
  23.             {
  24.                 cout << i+1  << " " << j+1  << endl;
  25.                 ++watch;
  26.             }
  27.         }
  28.     }
  29.     if (j > 0)
  30.     {
  31.         searchForPalindrom(arr, size - 1, watch);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment