求助大佬,66分,最后一个过不了
查看原帖
求助大佬,66分,最后一个过不了
1578600
A_567楼主2025/1/21 21:25
#include <iostream>
#include <stack>
#include<string>
#include<algorithm>
using namespace std;
string s;
int n = 0;
int t = 0;
stack<unsigned long long> stk;
signed main()
{
	cin >> t;
	while (t--)
	{
		cin >> n;
		for (int i = 1; i <= n; i++)
		{
			cin >> s;
			if (s == "push")
			{
				unsigned long long x = 0;
				cin >> x;
				stk.push(x);
			}
			else if (s == "pop")
			{
				if (stk.empty())
				{
					cout << "Empty" << endl;

				}
				else
				{
					stk.pop();

				}
			}
			else if (s == "query")
			{
				if (stk.empty())
				{
					cout << "Anguei!" << endl;

				}
				else
				{
					cout << stk.top() << endl;

				}
			}
			else
			{
				cout << stk.size() << endl;
			}
		}
	}
	while (!stk.empty())
	{
		stk.pop();
	}
	return  0;
}
2025/1/21 21:25
加载中...