66求调

B3614 【模板】栈

Niko840 @ 2024-11-21 13:07:38

#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
ll n,m,x;
string s;
stack<ll>a;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>m;
        for(int j=1;j<=m;j++)
        {
            cin>>s;
            if(s=="push")
            {
                cin>>x;
                a.push(x);
                x=0;
            }
            else if(s=="pop")
            {
                if(a.size())
                    a.pop();
                else
                    cout<<"Empty\n";
            }
            else if(s=="query")
            {
                if(a.size())
                    cout<<a.top()<<"\n";
                else
                    cout<<"Anguei!\n";
            }
            else if(s=="size")
            {
                cout<<a.size()<<"\n";
            }
        }
    }

    return 0;
}

by Rayminn @ 2024-11-21 13:44:17

多测没清空


|