72728abcd @ 2024-11-10 11:37:19
程序
#include<bits/stdc++.h>
using namespace std;
stack<unsigned long long> a;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n;
cin>>n;
for(int j=0;j<n;j++)
{
string b;
cin>>b;
if(b=="push")
{
unsigned long long c;
cin>>c;
a.push(c);
}
if(b=="pop")
{
if(!a.empty())
{
a.pop();
}
else
{
cout<<"Empty"<<endl;
}
}
if(b=="query")
{
if(!a.empty())
{
cout<<a.top()<<endl;
}
else
{
cout<<"Anguei!"<<endl;
}
}
if(b=="size")
{
cout<<a.size()<<endl;
}
while(!a.empty())
{
a.pop();
}
}
}
return 0;
}
by lan_xing_xing @ 2024-11-10 11:49:26
#include<bits/stdc++.h>
using namespace std;
stack<unsigned long long> a;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n;
cin>>n;
for(int j=0;j<n;j++)
{
string b;
cin>>b;
if(b=="push")
{
unsigned long long c;
cin>>c;
a.push(c);
}
if(b=="pop")
{
if(!a.empty())
{
a.pop();
}
else
{
cout<<"Empty"<<endl;
}
}
if(b=="query")
{
if(!a.empty())
{
cout<<a.top()<<endl;
}
else
{
cout<<"Anguei!"<<endl;
}
}
if(b=="size")
{
cout<<a.size()<<endl;
}
}
while(!a.empty())//一组数据结束后再清空栈
{
a.pop();
}
}
return 0;
}
by lan_xing_xing @ 2024-11-10 11:50:30
@72728abcd
by 72728abcd @ 2024-11-10 21:15:00
@lan_xing_xing 谢谢
by 72728abcd @ 2024-11-10 21:15:30
咱么俩互吧