Advertisement
WadeRollins2710

Excersise 3

Oct 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. //Ex no.3 - Tran Viet Anh - 12:17PM
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n; cin >> n;
  9.     int a[n];
  10.     for (int i = 0; i < n; i++)
  11.         cin >> a[i];
  12.     int start = 0, end, max = 0, maxStart, maxEnd;
  13.     for (int i = 1; i < n; i++)
  14.         if (a[i] < a[i - 1])
  15.         {
  16.             if (i - 1 - start > max)
  17.             {
  18.                 max = i - 1 - start;
  19.                 maxStart = start;
  20.                 maxEnd = i - 1;
  21.             }
  22.             start = i;
  23.         }
  24.     if (n - 1 - start > max)
  25.     {
  26.         maxStart = start;
  27.         maxEnd = n - 1;
  28.     }
  29.     for (int i = maxStart; i <= maxEnd; i++)
  30.         cout << a[i] << " ";
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement