33pts HELP!!!!!!!! 求调!!!!!!

B3614 【模板】栈

Tang15387021810 @ 2024-12-15 14:43:48

原题传送门

#include<iostream>
#include<cstdio>
#include<stack>
#include<string>
using namespace std;
long long t,n,x;
string s1;
stack<unsigned long long int> s;
int main()
{
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        cin>>n;
        for(int j=1;j<=n;j++)
        {
            cin>>s1;
            if(s1=="push")
            {
                cin>>x;
                s.push(x);  
            }
            if(s1=="pop")
            {
                if(!s.empty())  s.pop();
                else            cout<<"Empty"<<endl;
            }
            if(s1=="query")
            {
                if(!s.empty())  cout<<s.top()<<endl;                    
                else            cout<<"Anguei!"<<endl;
            }
            if(s1=="size")  cout<<s.size()<<endl;
        }
    }
    while(!s.empty())   s.pop();
    return 0;
}

by leoljx @ 2024-12-15 14:52:31

把变量x的类型设成ull


by Rigil_Kent @ 2024-12-15 14:56:53

倒数第 3 行放到第 1 个循环里面。


by Tang15387021810 @ 2024-12-15 14:58:48

@Rigil_Kent谢谢!!!!!


by Tang15387021810 @ 2024-12-15 14:59:18

@Rigil_Kent已过


|