G16|A605.详细题解
2026-09-27 18:41:26
发布于:广东
2阅读
0回复
0点赞
较详细题解
使用基础STL栈
·st.push(x)//入栈
·st.top()//获取最顶值
·st.pop()//删除最顶值
综上,写出代码:
#include<bits/stdc++.h>
using namespace std;
//初始化
int n;
stack<int>st;
int main(){
//输入
cin >> n;
//入栈
for(int i = 0;i<n;i++){
int x;
cin >> x;
st.push(x);
}
//输出;
for(int i = 0;i<n;i++){
cout << st.top() << ' ';
st.pop();
}
return 0;
}
时间复杂度是
O(2n)
这里空空如也


有帮助,赞一个