33分求助
查看原帖
33分求助
1395986
vscdr_楼主2024/10/19 11:06

真的不知道错哪了

#include<bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0),cout.tie(0);
	int t; cin >> t;
	while (t--)
	{
		stack<unsigned long long> stk;
		int n; cin >> n;
		string s;
		while (n-- && cin >> s)
		{
			if (s == "push")
			{
				int x; cin >> x;
				stk.push(x);
			}
			else if (s == "query") //输出栈顶元素
			{
				if (stk.empty())
				{
					cout << "Anguei!" << '\n';
				}
				else
				{
					cout << stk.top() << '\n';
				}
			}
			else if (s == "size")//输出长度
			{
				cout << stk.size() << '\n';
			}
			else if (s == "pop") //弹出一个元素
			{
				if (stk.empty())
				{
					cout << "Empty" << '\n';
				}
				else {
					stk.pop();
				}
			}

		}
	}

	return 0;
}
2024/10/19 11:06
加载中...