33分求助!QWQ
查看原帖
33分求助!QWQ
760992
guoduor楼主2023/8/26 10:48

交了十几遍都是33分,大佬求助

#include <cstdio>
#include <iostream>
#include <stack>

using namespace std;

stack<unsigned long long> s;

int main()
{
        unsigned long long T,n,x;
        string str;
        scanf("%lld",&T);
        for(int i=1;i<=T;i++)
        {
                scanf("%lld",&n);
                for(int j=1;j<=n;j++)
                {
                        cin >> str;
                        if(str == "push")
                        {
                                scanf("%lld",&x);
                                s.push(x);
                        }
                        else if(str == "pop")
                        {
                                if(s.empty())
                                {
                                        printf("Empty\n");
                                }
                                else
                                {
                                        s.pop();
                                }
                        }
                        else if(str == "query")
                        {
                                if(s.empty())
                                {
                                    printf("Anguei!\n");
                                }
                                else
                                {
                                        printf("%lld\n",s.top());
                                }
                        }
                        else if(str == "size")
                        {
                                printf("%ld\n",s.size());
                        }
                }
                while(!s.empty())
                {
                        s.pop();
                }
        }
        return 0;
}
2023/8/26 10:48
加载中...