得分率%30求改正
原题链接:658.模拟栈操作2026-08-26 17:07:26
发布于:山东
#include<bits/stdc++.h>
using namespace std;
stack<int> sta;
int n,x;
string k;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>k;
if(k=="push"){
cin>>x;
sta.push(x);
}
if(k=="pop"){
if(sta.empty()){
cout <<"pop fail"<<endl;
continue;
}
cout <<"pop "<<sta.top()<<endl;
sta.pop();
}
if(k=="top"){
if(sta.empty()){
cout <<"top fail"<<endl;
continue;
}
cout <<"top = "<<sta.top()<<endl;
}
if(k=="size"){
cout <<sta.size()<<endl;
}
if(k=="empty"){
if(sta.empty()){
cout <<"yes"<<endl;
}
else{
cout <<"no"<<endl;
}
}
}
return 0;
}
这里空空如也



















有帮助,赞一个