Advertisement
STANAANDREY

Next greatest element

Jul 3rd, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     const int n=8;
  7.     int v[]= {3,4,20,6,15,2,1,7},max_right;
  8.     max_right=v[n-1];
  9.     for (int i=n-1; i>-1; i--)
  10.         if (max_right>v[i])
  11.             v[i]=max_right;
  12.         else
  13.             max_right=v[i];
  14.  
  15.             for (int i=0;i<n;i++)
  16.                 cout<<v[i]<<' ';
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement