33分求调

B3614 【模板】栈

wuyuemumuxin @ 2024-08-28 18:58:04

#include<bits/stdc++.h>
using namespace std;
int main(){
    unsigned long long n;
    cin>>n;
    while(n--){
        stack<unsigned long long> s;
        unsigned long long m;
        string x;
        cin>>m;
        while(m--){
            cin>>x;
            if(x[0]=='q'){
                if(s.empty())cout<<"Anguei!\n";
                else cout<<s.top()<<"\n";
            }else if(x[0]=='s')cout<<s.size()<<"\n";
            else if(x.size()==3){
                if(s.empty())cout<<"Empty\n";
                else s.pop();
            }else{
                int c;
                cin>>c;
                s.push(c);
            }
        }
    }
    return 0;
}

by SBBSBSBSBSB @ 2024-08-29 12:56:16

if(x[0]=='q')

改成

if(x=="query")

以此类推


by SBBSBSBSBSB @ 2024-08-29 12:56:49

不要偷懒


|