nhdnana @ 2024-12-23 20:36:56
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll t,n,top=0;
ll x;
ll st[100000000];
string a[505000];
int main()
{
cin>>t;
for(int i=1; i<=t; i++)
{
cin>>n;
top=0;
for(int j=1; j<=n; j++)
{
cin>>a[j];
if(a[j]=="push")
{
cin>>x;
st[++top]=x;
}
}
for(int l=1; l<=n; l++)
{
if(a[l]=="query")
{
if(top==0)
{
cout<<"Anguei!"<<"\n";
}
else
{
cout<<st[top]<<"\n";
}
}
if(a[l]=="pop")
{
if(top==0)
{
cout<<"Empty"<<"\n";
}
else
{
top--;
}
}
if(a[l]=="size")
{
cout<<top<<"\n";
}
}
}
return 0;
}
by TFXCXY @ 2024-12-24 21:52:12
求调+1
#include<bits/stdc++.h>
using namespace std;
long long T,n,x,a[100000005],top;
string cinn;
int main(){
cin>>T;
for(int i=1;i<=T;i++){
top=0;
cin>>n;
for(int j=1;j<=n;j++){
cin>>cinn;
if(cinn=="push"){
cin>>x;
a[++top]=x;
}
if(cinn=="pop"){
if(top>0) top--;
else cout<<"Empty\n";
}
if(cinn=="query"){
if(top>0) cout<<a[top]<<endl;
else cout<<"Anguei!\n";
}
if(cinn=="size") cout<<top<<endl;
}
}
return 0;
}
by sunnyboy1 @ 2024-12-26 19:56:13
@TFXCXY你这个需要把栈清空,而且要开unsigned long long