Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4.  
  5. #include <iostream>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. void find() {
  11.     int n, max = -10000, status = 0, m, left = 0, right = 0, big = 0, current = 1, equals = 1;
  12.     cout << "Enter the size of array:";
  13.     cin >> n;
  14.     int A[n];
  15.     for (int i = 0;i < n; i++) {
  16.         cin >> A[i];
  17.         if (i !=0 ) {
  18.             if (A[i] >= A[i-1] && status == 1) {
  19.                 current += 1;
  20.                 if (A[i] == A[i - 1]) {
  21.                     equals += 1;
  22.                 } else {
  23.                     equals = 1;
  24.                 }
  25.             }
  26.             if (A[i] <= A[i-1] && status == -1) {
  27.                 current += 1;
  28.                 if (A[i] == A[i - 1]) {
  29.                     equals += 1;
  30.                 } else {
  31.                     equals = 1;
  32.                 }
  33.             } else if (A[i] > A[i-1] && status == 0) {
  34.                 status = 1;
  35.                 current += 1;
  36.             }  else if (A[i] < A[i-1] && status == 0) {
  37.                 status = -1;
  38.                 current += 1;
  39.             }  else if (status == 0) {
  40.                 current += 1;
  41.             } else {
  42.                 if (current > big) {
  43.                     big = current;
  44.                     left = i - current;
  45.                 }
  46.                 current = 1 + equals;
  47.                 status *= (-1);
  48.                 equals = 1;
  49.             }
  50.             cout << current << " " << equals<< " " << status << endl;  
  51.                
  52.         }
  53.     }
  54.     if (current > big) {
  55.         big = current;
  56.         left = n - current;
  57.     }
  58.     //cout << i;
  59.     for (m = left;m < left + big; m++) {
  60.         cout << A[m] << " ";
  61.     }
  62. }
  63.  
  64.  
  65. int main()
  66. {
  67.     //1 0 0 3 3 2 1 0 -1
  68.     find();
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement