题解 | 【模板】栈的操作
【模板】栈的操作
https://www.nowcoder.com/practice/cdf02ea916454957b575585634e5773a?channelPut=tracker3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ll t;
cin>>t;
stack<ll>z;
while(t--)
{
string s;
cin>>s;
if(s=="push"){
int x;
cin>>x;
z.push(x);
}
else if(s=="size"){
cout<<z.size()<<endl;
}
else if(s=="pop"){
if(z.empty()){
cout<<"Empty"<<endl;
}
else z.pop();
}
else if(s=="query")
{
if(z.empty()){
cout<<"Empty"<<endl;
}
else cout<<z.top()<<endl;
}
}
return 0;
}