神犇求调QAQ

B3614 【模板】栈

vector_STL_ @ 2024-09-28 23:38:11

#include<bits/stdc++.h>
using namespace std;

void push(int a,vector<int>f){
    f.push_back(a);
}
void pop(vector<int>f){
    if(f.size()==0){
        cout<<"Empty"<<endl;
    }
    else{
        f.pop_back();
    }
}
void query(vector<int>f){
    if(f.size()==0){
        cout<<"Anguei!"<<endl;
    }
    else{
        cout<<f[f.size()-1]<<endl;
    }
}
void size(vector<int>f){
    cout<<f.size()<<endl;
}
int main() {
    int a;
    cin>>a;
    for(int i=1;i<=a;i++){
        vector<int>f;
        int b;
        cin>>b;
        for(int j=1;j<=b;j++){
            string s;
            getline(cin,s);
            if(s[0]=='p'&&s[1]=='u'&&s[2]=='s'&&s[3]=='h'){
                push((int)s[5]-48,f);
            }
            else if(s[0]=='p'&&s[1]=='o'&&s[2]=='p'){
                pop(f);
            }
            else if(s[0]=='q'&&s[1]=='u'&&s[2]=='e'&&s[3]=='r'&&s[4]=='y'){
                query(f);
            }
            else if(s[0]=='s'&&s[1]=='i'&&s[2]=='z'&&s[3]=='e'){
                size(f);
            }
        }
    }
    return 0;
}

by andycode @ 2024-09-29 08:03:40

@zch120526 x可能大于9


|