题解 | 【模板】栈的操作
【模板】栈的操作
https://www.nowcoder.com/practice/cdf02ea916454957b575585634e5773a
#include <cstdio>
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
int main() {
string co;
int n, x;
stack<int> a;
cin>>n;
while (n--) {
cin>>co;
if(co=="push"){
cin>>x;
a.push(x);
}
else if(co=="pop"){
if(a.empty()) printf("Empty\n");
else a.pop();
}
else if(co=="query"){
if(a.empty()) printf("Empty\n");
else printf("%d\n",a.top());
}
else if(co=="size"){
printf("%ld\n",a.size());
}
}
return 0;
}