vector
2024-01-23 20:34:41
发布于:上海
11阅读
0回复
0点赞
#include<iostream>
#include<vector>
using namespace std;
vector<int> s;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
string a;
cin>>a;
if(a=="empty")cout<<(s.empty()?"yes":"no")<<endl;
if(a=="push"){int k;cin>>k;s.push_back(k);}
if(a=="pop"){if(!s.empty()){cout<<"pop "<<s.back()<<endl;s.pop_back();}else cout<<"pop fail"<<endl;}
if(a=="size")cout<<"size = "<<s.size()<<endl;
if(a=="top"){if(!s.empty())cout<<"top = "<<s.back()<<endl;else cout<<"top fail"<<endl;}
}
return 0;
}
这里空空如也
有帮助,赞一个