#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    queue<int> q;
    for(int i=0; i<n; i++)
    {
        char a[15]={};
        scanf("%s",a);
        if(a[0]=='p')
        {
            if(a[1]=='u')
            {
                int x;
                scanf(" %d )",&x);
                q.push(x);
            }
            else if(!q.empty())
            {
                q.pop();
            }
        }
        else if(a[0]=='f')
        {
            if(q.empty())
                printf("-1\n");
            else
                printf("%d\n",q.front());
        }
        else if(a[0]=='b')
        {
            if(q.empty())
                printf("-1\n");
            else
                printf("%d\n",q.back());           
        }
        else if(a[0]=='s')
        {
            printf("%d\n",q.size());                
        }
        else
        {
            if(q.empty())
                printf("true\n");
            else
                printf("false\n");
        }
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: