#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
int n;
cin>>n;
int cnt = 0;
int top = cnt;
while (n--){
string s;
cin>>s;
if (s == "push"){
int k;//插入的数
cin>>k;
arr[cnt] = k;
top = cnt;
cnt++;
}
else if(s == "pop"){
arr[top] = 0;
top--;
cnt--;
}
else if(s == "empty"){
if (!arr[top]){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
else if(s == "query"){
cout<<arr[top]<<endl;
}
}
return 0;
}
关于如何用数组模拟栈 c++
最新推荐文章于 2024-10-07 14:04:39 发布