题解 | #【模板】队列#模拟队列

【模板】队列

https://www.nowcoder.com/practice/afe812c80ad946f4b292a26dd13ba549

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    queue<int> a;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s=="push")
        {
            int x;
            cin>>x;
            a.push(x);
        }
        else if(s=="pop")
        {
            if(a.empty())
                cout<<"error\n";
            else
            {    
                cout<<a.front()<<"\n";
                a.pop();
            }
        }
        else 
        {
            if(a.empty())
                cout<<"error\n";
            else
                cout<<a.front()<<"\n";
        }
    }
    return 0;
}

全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务