chenhouye @ 2024-10-02 13:15:13
#include<bits/stdc++.h>
using namespace std;
stack<unsigned long long>st;
int n,t;
unsigned long long x;
string s;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>s;
if(s=="push"){
scanf("%lld",&x);
st.push(x);
}
else if(s=="query"){
if(st.empty()) printf("Anguei!\n");
else printf("%lld\n",st.top());
}
else if(s=="pop"){
if(st.empty()) printf("Empty\n");
else st.pop();
}
else printf("%d\n",st.size());
}
}
return 0;
}
谢谢
by __galaxy_1202__ @ 2024-10-02 13:22:55
@chenhouye 每组数据是单独的,也就是说定义栈的代码要在输入n的前面
by RaymondOccam @ 2024-10-02 13:24:44
多测题注意初始化
by xudongyi1 @ 2024-10-02 13:44:28
多测不清空,__
by dongzirui0817 @ 2024-10-02 13:47:16
@chenhouye 肯定不止清空,清空错应该66分
by dongzirui0817 @ 2024-10-02 13:48:42
@chenhouye query 的输出方式错了,会把 stack 中的数强制转成 long long
输出
by chenhouye @ 2024-10-02 17:00:10
@20121202Tzy
@RaymondOccam
@xudongyi1
@dongzirui0817
谢谢以上大佬给各位添麻烦了,我真是太傻了
by ZYStream @ 2024-10-03 13:26:22
"push"要用单引号,'push'