Advertisement
daaaar

thething

Sep 25th, 2020
1,095
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. using namespace std;
  3.  
  4. int main() {
  5.  
  6.   int * nums = nullptr;
  7.   int num;
  8.   int n;
  9.  
  10.   int i, j, longest=1, len;
  11.  
  12.   // input order of array then allocate mem
  13.   cin >> n;
  14.   nums = new int[n];
  15.  
  16.   // input each num of sequence the store in array
  17.   for (i = 0; i < n; i++)
  18.     {
  19.       cin >> num;
  20.       nums[i] = num;
  21.     }
  22.  
  23. // do the thang
  24.   for(i=0; i<n; i++){
  25.     len=1;
  26.     for(j=i; j<n; j++){
  27.       if(nums[j+1]>nums[j]){
  28.     len++;
  29.       }
  30.     }
  31.     if(len>1 && len>longest){
  32.       longest=len;
  33.     }
  34.   }
  35.  
  36.   delete[] nums;
  37.   // if final value of len was 1, then no sequence exists.
  38.   if (longest == 1)
  39.     longest = -1;
  40.  
  41.   cout << longest << endl;
  42.  
  43.   return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement