66分求助!!!!
查看原帖
66分求助!!!!
1059553
MoHuaSAMA楼主2024/5/9 17:28
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

const int N = 1e6 + 10;

int t,n;
vector<unsigned long long int> stack;

void push(unsigned long long int x){
    stack.push_back(x);
}

void pop(){
    if(stack.size() == 0){
        cout << "Empty" << endl;
        return ;
    }
    stack.pop_back();
}

void query(){
    if(stack.size() == 0){
        cout << "Anguei!" << endl;
        return ;
    }
    cout << stack[stack.size() - 1] << endl;
}

void size(){
    cout << stack.size() << endl;
    return ;
}

void check(string op){
    // 判断操作类型
    //根据长度判断
    //调用
    if(op.size() == 5){
        query();
    }
    else if(op.size() == 4){
        if(op[0] == 'p'){
            unsigned long long int x;
            cin >> x;
            push(x);
        }
        else {
            size();
        }
    }
    else if(op.size() == 3){
        pop();
    }
}

int main(){
    cin >> t;
    for(int i = 0;i < t;i++){
        scanf("%d",&n);
        for(int j = 0;j < n;j++){
            string op;
            cin >> op;
            check(op);
        }
    }
    return 0;
}
2024/5/9 17:28
加载中...