求助,两红啊
查看原帖
求助,两红啊
1636963
zouhaoyang8888楼主2025/1/13 16:46
#include <bits/stdc++.h>
using namespace std;


int n , t;
string s;

int main()
{
	cin >> t;
	for(int i = 1 ; i <= t ; i++)
	{
		stack<int> st;
		cin >> n;
		for(int j = 1 ; j <= n ; j++)
		{
			cin >> s;
			if(s == "push")
			{
				int x;
				cin >> x;
				st.push(x);
			}
			else if(s == "pop")
			{
				if(st.empty()) cout << "Empty" << "\n";
				else st.pop();
			}
			else if(s == "query")
			{
				if(st.empty() == 0) cout << st.top() << "\n";
				else cout << "Anguei!" << "\n";
			}
			else if(s == "size")
			{
				cout << st.size() << "\n";
			}
		}
	}
	return 0;
}
2025/1/13 16:46
加载中...