Advertisement
allia

поиск подмассива доделать

Sep 14th, 2020
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.   long long a=0, n=0, z=0, max=0, min=0;
  9.   cin >> a;
  10.   int arr[a];
  11.  
  12.   for (int i=0; i<a; i++)
  13.   cin >> arr[i];
  14.    
  15.   for (int i=0; i<a-1; ++i)
  16.   {
  17.     if (abs(arr[i+1])-abs(arr[i])==1)
  18.     {
  19.       if (arr[i+1]<0 && arr[i]<0)
  20.        n++;
  21.         else if (arr[i+1]>0 && arr[i]>0)
  22.          z++;
  23.          else
  24.          {
  25.            n=0;
  26.            z=0;
  27.           }
  28.           if (max < z)
  29.           max = z;
  30.           if (min < n)
  31.           min = n;
  32.     }
  33.     else
  34.     {
  35.       z=0;
  36.       n=0;
  37.     }
  38.   }
  39.    if (max!=0)
  40.    cout << max+1;
  41.    else if(min!=0)
  42.    cout << min +1;
  43.    else cout << 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement