求助
查看原帖
求助
1135546
qwp____5_0_3楼主2025/1/12 21:21
#include<bits/stdc++.h>
using namespace std;
int T;
int n;
string s;
stack<int>st; 

int main()
{
	cin>>T;
	while(T--)
	{
		while(!st.empty())st.pop();
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>s;
			if(s=="push")
			{
				int x;
				cin>>x;
				st.push(x); 	
			}
			if(s=="query")
			{
				if(!st.empty())cout<<st.top()<<"\n\n";
				else cout<<"Anguei!\n\n"; 
			}
			if(s=="size")cout<<st.size()<<"\n\n";
			if(s=="pop")
			{
				if(!st.empty())st.pop();
				else cout<<"Empty\n\n";
			}
		}
	}

	return 0;
}
2025/1/12 21:21
加载中...