33求
查看原帖
33求
1328844
72728abcd楼主2024/11/10 11:13

程序

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,e=0;
	cin>>t;
	string ans[10001];
	for(int i=0;i<t;i++)
	{
		stack<unsigned long long int> a;
		int n;
		cin>>n;
		for(int j=0;j<n;j++)
		{
			string b;
			cin>>b;
			if(b=="push")
			{
				int c;
				cin>>c;
				a.push(c);
			}
			if(b=="pop")
			{
				if(!a.empty())
				{
					a.pop();
				}
				else
				{
					ans[e]+="Empty";
					e++;
				}
			}
			if(b=="query")
			{
				if(!a.empty())
				{
					cout<<a.top()<<endl;
				}
				else
				{
					ans[e]+="Anguei!";
					e++;
				}
			}
			if(b=="size")
			{
				ans[e]+=to_string(a.size());
				e++;
			}
		}
	}
	for(int i=0;i<e;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}
2024/11/10 11:13
加载中...