手打真累
2024-08-03 15:49:13
发布于:云南
4阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main(){
stack<int> st;
int q; cin >> q;
while(q--){
string way; cin >> way;
if(way == "empty" && st.empty()) cout << "yes\n";
else if(way == "empty" && !st.empty()) cout << "no\n";
else if(way == "push"){
int n; cin >> n;
st.push(n);
}else if(way == "pop" && st.empty()) cout << "pop fail\n";
else if(way == "pop" && !st.empty()){
cout << "pop " << st.top() << endl;
st.pop();
}else if(way == "top" && st.empty()) cout << "top fail\n";
else if(way == "top" && !st.empty()) cout << "top = " << st.top() << endl;
else cout << "size = " << st.size() << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个