66分求调QwQ

B3614 【模板】栈

YMS2333 @ 2024-09-16 21:38:40

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    vector<unsigned long long> v;
    int t;
    cin>>t;
    string caozuo;
    unsigned long long temp;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=0;i<n;++i)
        {
            cin>>caozuo;
            if(caozuo=="push")
            {
                cin>>temp;
                v.push_back(temp);
            }
            if(caozuo=="pop")
            {
                if(v.size()!=0)
                    v.pop_back();
                else
                    cout<<"Empty"<<endl;
            }
            if(caozuo=="query")
            {
                if(v.size()!=0)
                    cout<<v.back()<<endl;
                else
                    cout<<"Anguei!"<<endl;
            }
            if(caozuo=="size")
            {
                cout<<v.size()<<endl;
            }
        }
    }
}

by YMS2333 @ 2024-09-16 21:39:12

QwQ:;


by Yxy7952 @ 2024-09-16 22:01:44

@YMS2333

求关

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int t;
    cin>>t;
    string caozuo;
    unsigned long long temp;
    while(t--)
    {
        vector<unsigned long long> v;
        int n;
        cin>>n;
        for(int i=0;i<n;++i)
        {
            cin>>caozuo;
            if(caozuo=="push")
            {
                cin>>temp;
                v.push_back(temp);
            }
            if(caozuo=="pop")
            {
                if(v.size()!=0)
                    v.pop_back();
                else
                    cout<<"Empty"<<endl;
            }
            if(caozuo=="query")
            {
                if(v.size()!=0)
                    cout<<v.back()<<endl;
                else
                    cout<<"Anguei!"<<endl;
            }
            if(caozuo=="size")
            {
                cout<<v.size()<<endl;
            }
        }
    }
}

by dongzirui0817 @ 2024-09-16 22:03:11

@YMS2333 每次操作完要清空栈


by dongzirui0817 @ 2024-09-16 22:04:10

@YMS2333 加的:

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    vector<unsigned long long> v;
    int t;
    cin>>t;
    string caozuo;
    unsigned long long temp;
    while(t--)
    {
        int n;
        cin>>n;
        v.clear();  //clear
        for(int i=0;i<n;++i)
        {
            cin>>caozuo;
            if(caozuo=="push")
            {
                cin>>temp;
                v.push_back(temp);
            }
            if(caozuo=="pop")
            {
                if(v.size()!=0)
                    v.pop_back();
                else
                    cout<<"Empty"<<endl;
            }
            if(caozuo=="query")
            {
                if(v.size()!=0)
                    cout<<v.back()<<endl;
                else
                    cout<<"Anguei!"<<endl;
            }
            if(caozuo=="size")
            {
                cout<<v.size()<<endl;
            }
        }
    }
}

by Yxy7952 @ 2024-09-16 22:05:24

@dongzirui0817

baby无耻 QWQ


by dongzirui0817 @ 2024-09-16 22:09:44

@Yxy7952 ……


by YMS2333 @ 2024-09-17 09:00:25

@dongzirui0817 谢谢大佬!!


by YMS2333 @ 2024-09-17 09:01:19

@Yxy7952 谢谢!!


|