66pts求条!!!

B3614 【模板】栈

tanruiqing @ 2024-11-01 17:14:54

手写栈,求大佬帮忙看一下OrzOrz

#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;

struct mystack{
    int Stack[5000005];
    int len;
    void push(int a){
        Stack[++len] = a;
    }
    int top(){
        return ((len == 0) ? -1 : Stack[len]);
    }
    bool pop(){
        Stack[len] = 0;
        if(len == 0)return false;
        len--;
        return true;
    }
    int empty(){
        return len;
    }
    void memset_stack(){
        for(int i = 0  ; i <= len ; i++)Stack[i] = 0;
    }
}Handwriting_stacks;

int n,t;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--){
        cin >> n;
        string s = "";
        for(int i = 1 ; i <= n ; i++){
            cin >> s;
            if(s == "push"){
                int x;
                cin >> x;
                Handwriting_stacks.push(x);
            }else if(s == "pop"){
                if(Handwriting_stacks.pop() == false){
                    cout << "Empty\n";
                }
            }else if(s == "query"){
                if(Handwriting_stacks.top() == -1){
                    cout << "Anguei!\n";
                }else{
                    cout << Handwriting_stacks.top() << '\n';
                }
            }else if(s == "size"){
                cout << Handwriting_stacks.empty() << '\n';
            }
        }
        Handwriting_stacks.memset_stack();
    }
    return 0;
}

|