66分求条
查看原帖
66分求条
826847
__hanzhenhong__楼主2024/11/28 21:02
#include<iostream>
#include<stack>
using namespace std;
#define ll unsigned long long
ll T;
int main()
{
	cin>>T;
	while(T--)
	{
	    stack<ll> st;
		ll n;
		cin>>n;
		string s;
		int m;
		for(ll i=1;i<=n;i++)
		{
			cin>>s;
			if(s=="push")
			{
				cin>>m;
				st.push(m);
			}
			else if(s=="query")
			{
				if(st.empty())
				{
					cout<<"Anguei!"<<endl;
				}
				else
				{
					cout<<st.top()<<endl;
				}
			}
			else if(s=="pop")
			{
				if(st.empty())
				{
					cout<<"Empty"<<endl;
				}
				else
				{
					st.pop();
				}
			}
			else if(s=="size")
			{
				cout<<st.size()<<endl;
			}
		}
		while(st.size()!=0)
		{
			st.pop();
		}
	}
	return 0;
}
2024/11/28 21:02
加载中...