SadmanHafiz

Cf_contest_

Oct 7th, 2021
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1.  #include <bits/stdc++.h>
  2.     using namespace std;
  3.     int mx(int a[],int l, int r)
  4.     {
  5.         int m = 0;
  6.         for(int i = l ; i <= r  ; i++)
  7.         {
  8.             if( a[i] > m)
  9.                 m = a[i];
  10.         }
  11.         return m;
  12.     }
  13.  
  14.     int main()
  15.     {
  16.        
  17.        int t ;
  18.        cin >> t;
  19.  
  20.        while(t--)
  21.        {
  22.        
  23.        int n ,p = 0;
  24.        cin >> n;
  25.        int a[n];
  26.  
  27.        for(int i = 0; i < n ; i++)
  28.        {
  29.             cin >> a[i];
  30.        }
  31.  
  32.        for(int i = 0 ; i < n ; i++)
  33.        {
  34.             for(int j = i ; j < n ;  j++ )
  35.             {
  36.                  p = mx(a,i,j);
  37.                  if(p)
  38.                  cout << p << " ";              
  39.             }
  40.        }
  41.        cout << endl;
  42.      }
  43.  
  44.  }
Advertisement
Add Comment
Please, Sign In to add comment