HuZhenYuan @ 2024-11-16 21:41:20
#include <bits/stdc++.h>
using namespace std;
int t,n;
string x;
stack<long long>s;
int main()
{
cin>>t;
for(int i=1;i<=t;i++)
{
scanf("%d",&n);
for(int j=1;j<=n;j++)
{
cin>>x;
if(x=="push")
{
int z;
cin>>z;
s.push(z);
}
if(x=="query")
{
if(s.empty())
cout<<"Anguei!"<<endl;
else
cout<<s.top()<<endl;
}
if(x=="pop")
{
if(s.empty())
cout<<"Empty"<<endl;
else
s.pop();
}
if(x=="size")
{
cout<<s.size()<<endl;
}
}
while(!s.empty())
s.pop();
}
return 0;
}
以上为代码!
by ___AaAa_bBcCd___ @ 2024-11-16 21:50:11
@HuZhenYuan 要开 unsigned long long。
#include <bits/stdc++.h>
using namespace std;
int t,n;
string x;
stack<unsigned long long>s;
int main(){
cin>>t;
for(int i=1;i<=t;i++){
scanf("%d",&n);
for(int j=1;j<=n;j++){
cin>>x;
if(x=="push"){
unsigned long long z;
cin>>z;
s.push(z);
}
else if(x=="query"){
if(s.empty())cout<<"Anguei!"<<endl;
else cout<<s.top()<<endl;
}
else if(x=="pop"){
if(s.empty())cout<<"Empty"<<endl;
else s.pop();
}
else if(x=="size")
cout<<s.size()<<endl;
}
while(!s.empty())s.pop();
}
return 0;
}
by HuZhenYuan @ 2024-11-16 21:55:56
@_AaAabBcCd谢谢你,我会了!