Result: Accepted
Time: 6ms
Memory: 1760kB
#include <cstdio>
#include <iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<deque>
using namespace std;
int n,m,i,j,k;
int main()
{
scanf("%d %d",&n,&m);
char s[114];
deque<int>q;
while(m--){
scanf("%s %d",s,&k);
if((!strcmp("pushLeft",s)||(!strcmp("pushRight",s))))
{
if(q.size()==n)
puts("The queue is full");
else
{
if(!strcmp("pushLeft",s)){
q.push_back(k);
printf("Pushed in left: %d\n",k);
}
if(!strcmp("pushRight",s)){
q.push_front(k);
printf("Pushed in right: %d\n",k);
}
}
}
if((!strcmp("popLeft",s)||(!strcmp("popRight",s)))){
if(q.size()==0)
puts("The queue is empty");
else
{
if(!strcmp("popLeft",s)){
printf("Popped from left: %d\n",q.back());
q.pop_back();
}
if(!strcmp("popRight",s)){
printf("Popped from right: %d\n",q.front());
q.pop_front();
}
}
}
}
return 0;
}