题目描述
输入样例
5
3 4 2 7 5
输出样例
-1 3 -1 2 2
参考代码
#include <iostream>
using namespace std;
const int N = 100010;
int stk[N], top;
int n, x;
int main()
{
cin >> n;
while (n--)
{
cin >> x;
while (top && stk[top] > x) top--;
if (!top) cout << -1 << ' ';
else cout << stk[top] << ' ';
stk[++top] = x;
}
return 0;
}