33分!!
查看原帖
33分!!
969320
Aoxiangcar楼主2023/10/13 18:01
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
stack<int>s;
int main()
{
    int t,n;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        for(int j=0;j<n;j++)
        {
            string a;
            cin>>a;
            if(a=="push")
            {
                long long b;
                cin>>b;
                s.push(b);
            }
            else
            {
                if(a=="query")
                {
                    if(s.size()==0)
                    cout<<"Anguei!"<<endl;
                    else
                    cout<<s.top()<<endl;
                }
                else
                {
                    if(a=="pop")
                    {
                        if(s.size()==0)
                        {
                            cout<<"Empty"<<endl;
                        }
                        else
                        s.pop();
                    }
                    else
                    if(a=="size")
                    {
                        cout<<s.size()<<endl;
                    }
                }
            }
        }
        while(s.size()>0)
        s.pop();
    }
    return 0;
}
2023/10/13 18:01
加载中...