33分求调
查看原帖
33分求调
1330072
Relisc楼主2024/6/30 22:31
#include<iostream>
using namespace std;
const int N=100010;
int top;
int s[N];

void push(unsigned long long x)
{
    s[++top]=x;
}

void query(){
    if(top == 0)    cout<<"Anguei!"<<endl;
    else{
        int t=s[top];
        cout<< t <<endl;
    }
}


void pop(){
    if( top == 0)  cout<<"Empty"<<endl;
    else top--;
}

void size(){
    cout<< top <<endl;
}



int main(){
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        
        while(n--)
        {
            string a;
            cin>>a;
            if(a == "push")    {
                unsigned long long  x;
                cin>>x;
                push(x);
            }
            else if(a == "pop")      pop();
            else if(a == "query")    query();
            else if(a == "size")     size();
        }
        
        top=0;//多次测试需要清空数据
        
    }
    
}

2024/6/30 22:31
加载中...