又有一个小萌新WA了,求助!!!
查看原帖
又有一个小萌新WA了,求助!!!
467431
ScrBaiYang楼主2022/8/16 17:45
#include<bits/stdc++.h>

using namespace std;

long long t,n,x;

string tw;

int main()
{
    cin>>t;
    for(long long i=1;i<=t;i++)
    {
    	stack<long long>s;
    	cin>>n;
    	for(long long j=1;j<=n;j++)
    	{
    		cin>>tw;
    		if(tw=="push")
    		{
    			cin>>x;
    			s.push(x);
			}
			else if(tw=="pop")
			{
				if(!s.empty())
				{
					s.pop();
				}
				else
				{
					cout<<"Empty"<<endl;
				}
			}
			else if(tw=="query")
			{
				if(!s.empty())
				{
					cout<<s.top()<<endl;
				}
				else
				{
					cout<<"Anguei!"<<endl;
				}
			}
			else if(tw=="size")
			{
				cout<<s.size()<<endl;
			}
		}
	}
    return 0;
}

太合理了,对叭

2022/8/16 17:45
加载中...