tangyiqi @ 2024-11-02 19:49:13
#include <bits/stdc++.h>
using namespace std;
int t;
stack<int>aa;
string order;
int main() {
scanf("%d",&t);
while(t--){
int a;
scanf("%d",&a);
while(a--){
cin>>order;
if(order == "push"){
int x;
scanf("%d",&x);
aa.push(x);
}
else if(order == "pop"){
if(aa.size() == 0){
printf("Empty\n");
continue;
}
aa.pop();
}
else if(order == "query"){
if(aa.size() == 0){
printf("Anguei!\n");
continue;
}
printf("%d\n",aa.top());
}
else if(order == "size")printf("%d\n",aa.size());
}
}
return 0;
}
by Enthon_Yuan @ 2024-11-02 19:50:10
多测不清空,____。
by __LTZ__ @ 2024-11-03 10:21:59
这属于经典的:
by __LTZ__ @ 2024-11-03 10:24:13
还有一点,此题数据是2的64次方,如果你开的是int或者long long都会爆掉,应该换成string
by ZzqAndy0728 @ 2024-11-03 11:21:53
@LTZ unsigned long long也可以