33
查看原帖
33
1074889
zg_ji楼主2023/11/6 19:04
#include<bits/stdc++.h>
using namespace std;

#define int long long
int T;
int n;
stack <int> s;

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--)
	{
		while(!s.empty()) s.pop(); 
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			string ss;
			cin>>ss;
			if(ss=="push")
			{
				int x;
				cin>>x;
				s.push(x);
			}
			else if(ss=="pop")
			{
				if(s.empty()) cout<<"Empty"<<endl;
				else s.pop();
			}
			else if(ss=="query")
			{
				if(s.empty()) cout<<"Anguei!"<<endl;
				else cout<<s.top()<<endl;
			}
			else cout<<s.size()<<endl;
		}
	}
	
	return 0;
	
}
2023/11/6 19:04
加载中...