哪里错了
查看原帖
哪里错了
1162831
HBQDCQ楼主2024/5/10 01:11
#include<iostream>
#include<string>
using namespace std;
struct Stack {
    int top, a[255];
    void inti() {
        top = 0;
    }
    void push(unsigned long long x) {
        a[++top] = x;
    }
    void pop() {
        if (top > 0)
            top--;
    }
}z;

int main() {
    int T,n;
    string t;
    unsigned long long x;
    cin >> T;
    for (int i = 0; i < T; i++) {
        z.inti();
        cin >> n;
        for (int j= 0; j < n; j++) {
            cin >> t;
            if (t == "push") {
                cin >> x;
                z.push(x);
            }
            if (t == "query") {
                if (z.top == 0)
                    cout << "Anguei!";
                else
                    cout << z.a[z.top];
                cout << endl;
            }
            if (t == "pop") {
                if (z.top == 0) {
                    cout << "Empty";
                    cout << endl;
                }
                else
                    z.pop();
            }
            if (t == "size") {
                cout << z.top;
                cout << endl;
            }
        }
        cin.ignore();
    }
    return 0;
}
2024/5/10 01:11
加载中...