正经题解
2025-07-11 16:40:29
发布于:浙江
6阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
stack<int> a;
int main(){
    int t;
    cin >> t;
    while(t--){
        string n;
        cin >> n;
        if(n=="push"){
            int m;
            cin >> m;
            a.push(m);
        }else if(n=="pop"){
            if(a.size()>0){
                
                cout << "pop "<<a.top()<<endl;
                a.pop();
            }else cout << "pop fail\n";
        }else if(n=="top"){
            if(a.size()>0){
                cout <<"top = "<< a.top()<<endl;
            }else cout << "top fail\n";
        }else if(n=="size"){
            cout << "size = "<<a.size()<<endl;
        }else if(n=="empty"){
            if(a.size()>0)cout <<"no\n";
            else cout << "yes\n";
        }
    }
    return 0;
}
这里空空如也







有帮助,赞一个