警钟敲烂
查看原帖
警钟敲烂
1202918
cpulxb楼主2024/5/3 11:25
  • 0到2640到2^{64},说明了一定要用unsigned long long,因为long long 的正数范围最大是263−12^{63}-1,用long long会爆

  • 第二点,就是要栈清空,我用的是数组模拟栈的过程,完全没用stl,所以不清空也是不会错,因为我感觉我的tt每次会变为0,相当于清空了

    本小白刚学栈,欢迎大佬来指出问题

#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long//1.要unsigned long long,long long 会错 
const int N=1e6+5;
int x;
int tt;
int stk[N];
signed main()
{   int t;
    cin>>t;string s;
    while(t--)
    {
        int n;cin>>n;tt=0;//2.栈清空
        while(n--)
        {
            cin>>s;
            if(s=="push")
            {
                
                cin>>x;
                stk[++tt]=x;
            }
            else if(s=="query")
            {
                if(tt>0)cout<<stk[tt]<<endl;
                else printf("Anguei!\n");
            }
            else if(s=="size")
            {
                printf("%d\n",tt);
            }
            else if(s=="pop")
            {
                if(tt>0)tt--;
                else printf("Empty\n");
            }
            
        }
    }
    return 0;
}
2024/5/3 11:25
加载中...