题目链接:https://www.acwing.com/problem/content/description/832/
题目如下:
#include <iostream>
#include <stack>
#include <climits>
using namespace std;
const int N=INT_MAX;//包含在头文件<climits>中
int main(){
stack<int> stk;//=new stack<int>(N);
int n,cnt;
cin>>n;
while(n--){
int x;
cin>>x;
while(stk.size()&&x<=stk.top()) stk.pop();//如果栈不为空,且栈顶元素比当前元素的值大,则需pop()
if(stk.empty()) cout<<"-1"<<" ";
else cout<<stk.top()<<" ";
stk.push(x);
}
cout<<endl;
return 0;
}