Skip to content

Instantly share code, notes, and snippets.

@OmarJH
Created May 12, 2015 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OmarJH/f6a3a5a8c2b523c248bd to your computer and use it in GitHub Desktop.
Save OmarJH/f6a3a5a8c2b523c248bd to your computer and use it in GitHub Desktop.
Sunset
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <int> a;
vector <int> ans;
int n,maxx=0,t;
cin >> t;
while (t--)
{
cin >> n;
a.push_back(n);
}
maxx = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
if (a[i] > maxx)
{
ans.push_back(a[i]);
maxx = a[i];
}
}
for (int i = ans.size()-1; i >=0; i--)
{
cout << ans[i];
if (i!=0)
cout<< " ";
}
cin >> n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment