chenqile @ 2024-11-07 21:09:27
#include <bits/stdc++.h>
using namespace std;
int main(){
int t, n;
string c;
stack<int> a;
cin>>t;
for(int i=0;i<t;i++){
cin>>n;
for(int j=0;j<n;j++){
cin>>c;
if(c[2]=='s'){
int q;
cin>>q;
a.push(q);
}
if(c[2]=='p'){
if(a.empty()) printf("Empty\n");
else a.pop();
}
if(c[2]=='e'){
if(a.empty()) printf("Anguei!\n");
else cout<<a.top()<<endl;
}
if(c[2]=='z'){
cout<<a.size()<<endl;
}
}
}
return 0;
}
by HZHDCM @ 2024-11-07 21:17:07
@chenqile 要开unsigned long long
by chenqile @ 2024-11-07 21:23:11
@HZHDCM 开ull还是WA一个点
by ikikun @ 2024-11-07 21:27:30
@chenqile 清空栈
by Ybll_ @ 2024-11-07 21:29:27
用unsigned long long int
by Ybll_ @ 2024-11-07 21:31:30
还有栈每次都要清空
by Ybll_ @ 2024-11-07 21:31:51
#include <bits/stdc++.h>
using namespace std;
int main(){
unsigned long long int t, n;
string c;
cin>>t;
for(unsigned long long int i=0;i<t;i++){
cin>>n;
stack<unsigned long long int> a;
for(unsigned long long int j=0;j<n;j++){
cin>>c;
if(c[2]=='s'){
unsigned long long int q;
cin>>q;
a.push(q);
}
if(c[2]=='p'){
if(a.empty()) printf("Empty\n");
else a.pop();
}
if(c[2]=='e'){
if(a.empty()) printf("Anguei!\n");
else cout<<a.top()<<endl;
}
if(c[2]=='z'){
cout<<a.size()<<endl;
}
}
}
return 0;
}
by Ybll_ @ 2024-11-07 21:32:06
求关