#include<bits/stdc++.h>
#include<stack>
using namespace std;
stack<unsigned long long> st;
unsigned long long x;
int main(){
unsigned long long t,n;
cin>>t>>n;
string s;
for(int i=1;i<=t;i++){
for(int j=1;j<=n;j++){
cin>>s;
if(s=="push"){
cin>>x;
st.push(x);
}
else if(s=="query"){
if(st.empty()) cout<<"Anguei!"<<endl;
else cout<<st.top()<<endl;
}
else if(s=="pop") {
if(st.empty()) cout<<"Empty"<<endl;
else st.pop();
}
else if(s=="size") cout<<st.size()<<endl;
}
}
return 0;
}
一开始用数组来模拟栈,结果不对。
然后我又用的栈,得了 33 分(#2 AC),不知道哪里错了。
此蒟蒻五年级,请求大佬相助 QWQ。