33pts求助
查看原帖
33pts求助
251074
学习柯学楼主2023/9/7 20:02
#include<bits/stdc++.h>
using namespace std;
stack <unsigned long long> s;
unsigned long long i, n, x, opt, T, len;
string st;
int main()
{
	cin>>T;
	while(T--)
	{
		cin>>n;
		len=0;
		for(i=1;i<=n;i++)
		{
			cin>>st;
			if(st=="push")
			{
				cin>>x;
				s.push(x);
				len++;
			}
			if(st=="size")
			{
				cout<<len<<endl;
			}
			if(st=="pop")
			{
				if(s.empty())
				{
					cout<<"Empty"<<endl;
				}
				else {
					s.pop();
				}
			}
			if(st=="query")
			{
				if(s.empty())
				{
					cout<<"Anguei!"<<endl;
				}
				else {
					cout<<s.top()<<endl;
				}
			}
		}
		while(!s.empty())
		{
			s.pop();
		}
	}
 	return 0;
}

2023/9/7 20:02
加载中...