社区讨论

求大佬找错,只能过样例

B3614【模板】栈参与者 4已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@lo8bzjxi
此快照首次捕获于
2023/10/27 16:08
2 年前
此快照最后确认于
2023/10/27 16:08
2 年前
查看原帖
CPP
#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef unsigned long long int ull;
const int N = 1e6 + 10;

ull stk[N];
int tt=-1;

void push(int x)
{
    stk[++tt]=x;
}

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

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int t;
    cin>>t;
    while(t--)
    {
        memset(stk,-1,sizeof stk);
        tt=-1;
        int n;
        cin>>n;
        while(n--)
        {
            string op;
            cin>>op;
            if(op=="push") 
            {
                ull x;
                cin>>x;
                push(x);
            }
            else if(op=="query")
            {
                if(tt>-1)
                    cout<<stk[tt]<<endl;
                else cout<<"Anguei!"<<endl;
            }
            else if(op=="size")
            {
                cout<<tt+1<<endl;
            }
            else 
            {
                pop();
            }
        }
    }
    return 0;
}

回复

5 条回复,欢迎继续交流。

正在加载回复...