AKIOI_GO @ 2024-09-19 20:52:54
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1000001],top=0,t,n,x;
string s;
int main(){
cin>>t;
while(t--){
cin>>n;
while(n--){
cin>>s;
top=0;
if(s=="push"){
cin>>x;
a[top++]=x;
}else if(s=="pop"){
if(top>0)
top--;
else
cout<<"Empty\n";
}else if(s=="query"){
if(top>0)
cout<<a[top-1]<<'\n';
else
cout<<"Anguei!\n";
}else
cout<<top<<'\n';
}
}
return 0;
}
提交记录
by microchip @ 2024-09-19 20:57:55
“多测不清空,_____”
by NC20061226 @ 2024-09-19 21:13:07
多测不清空,爆零两行泪。
每一次 for 循环之前都要重置一遍栈。
by AKIOI_GO @ 2024-10-02 18:31:34
谢谢
by AKIOI_GO @ 2024-10-02 18:32:16
@NC20061226 top=0了
by AKIOI_GO @ 2024-10-24 20:50:52
@microchip top=0了