来救救孩子吧!(33分求助)
查看原帖
来救救孩子吧!(33分求助)
713098
Koei楼主2023/4/19 22:44
#include <bits/stdc++.h>
using namespace std;
unsigned long long int w,n;
string d;
stack <unsigned long long int> s;
int main ()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>w;
		while(!s.empty())
		{
			s.pop();
		}
		for(int j=1;j<=w;j++)
		{
			cin>>d;
			if(d=="pop")
			{
				if(s.empty())
				{
					cout<<"Empty"<<"\n";
				}
				else
				{
					s.pop();
				}
			}
			if(d=="push")
			{
				int x;
				cin>>x;
				s.push(x);
			}
			if(d=="size")
			{
				int q;
				q=s.size();
				cout<<q<<"\n";
			}
			if(d=="query")
			{
				if(!s.empty())
				{
					int e=s.top();
					cout<<e<<"\n";
				}
				else
				{
					cout<<"Anguei!"<<"\n";
				}
			}
		}
	}
	return 0;
}
2023/4/19 22:44
加载中...