66分求调

B3614 【模板】栈

lwq0220 @ 2024-09-07 15:13:16

66分求调

#include<bits/stdc++.h>
using namespace std;
unsigned long long t,n,f[1000005],r=0;
int main()
{
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++){
            string s;
            cin>>s;
            if(s=="push"){
                unsigned long long x;
                cin>>x;
                f[++r]=x; 
            }
            if(s=="pop"){
                if(r<=0){
                    cout<<"Empty"<<endl;
                }
                else r--;
            }
            if(s=="query"){
                if(r<=0){
                    cout<<"Anguei!"<<endl;
                }
                else{
                    cout<<f[r]<<endl;
                }
            }
            if(s=="size"){
                cout<<r<<endl;
            }
        }
    }
}

by goIdie @ 2024-09-07 15:38:15

@lwq0220 清空栈


by Lawrenceling @ 2024-09-07 15:43:02

这么致命的错误还能拿 66 分。。。

多测不清空,抱灵(好像没有)两行泪。


by Lawrenceling @ 2024-09-07 15:43:14

@lwq0220


by yhzx2023gsq @ 2024-09-07 23:04:20

@lwq0220

楼主请看

↓↓↓

#include<bits/stdc++.h>
using namespace std;
unsigned long long T,n,a[1000005],tt;
void init()//栈的初始化
{
    tt=0; 
 } 
void pu(unsigned long long x)//栈顶输入x
{
    a[++tt]=x;
 } 
void po()//弹出栈顶
{
    if(tt<=0)
        cout<<"Empty"<<endl;
    else tt--; 
 } 
void que()//输出栈顶元素
{
    if(tt<=0)
        cout<<"Anguei!"<<endl;
    else 
        cout<<a[tt]<<endl; 
 } 
int size()//返回元素个数
{
    return tt;
 } 
int main()
{
    cin>>T;
    while(T--){
        init();
        cin>>n;
        while(n--){
            string s;
            cin>>s;
            unsigned long long x;
            if(s=="push")
            {
                cin>>x;
                pu(x);
            }
            else if(s=="pop"){
                po();
            }
            else if(s=="query"){
                que();
            }
            else 
            {
                cout<<size()<<endl;
             } 
        }
    }
    return 0;
}

by yhzx2023gsq @ 2024-09-07 23:05:27

道爷我成了!!!


by lwq0220 @ 2024-09-08 15:17:06

@goIdie 感谢dalao


by lwq0220 @ 2024-09-08 15:22:38

@Lawrence2011 哈哈,感谢dalao


|