C++初学者66分求助!
查看原帖
C++初学者66分求助!
740610
Gospodaru楼主2023/8/2 18:59

B3614

#include <bits/stdc++.h>
using namespace std;
stack<unsigned long long> s;
unsigned long long t,k,x;
string st;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>k;
		for(int j = 1;j <= k;j++)
		{
			cin>>st;
			if(st == "push")
			{
				cin>>x;
				s.push(x);
			}
			else if(st == "query")
			{
				if(s.empty())
				{
					cout<<"Anguei!\n";
				}
				else
				{
					cout<<s.top()<<"\n";
				}
			}
			else if(st == "size")
			{
				cout<<s.size()<<"\n";
			}
			else
			{
				if(s.empty())
				{
					cout<<"Empty\n";
				}
				else
				{
					s.pop();
				}
			}
		}
	}
	
	return 0;
}
2023/8/2 18:59
加载中...