一、题目
活动 - AcWing系统讲解常用算法与数据结构,给出相应代码模板,并会布置、讲解相应的基础算法题目。https://www.acwing.com/problem/content/832/
二、题解
#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int s[N], top, n;
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
int x = 0;
cin >> x;
while (top && s[top] >= x) top--;
if (top) cout << s[top] << " ";
else cout << "-1 ";
s[++top] = x;
}
return 0;
}