Result: Accepted
Time: 3ms
Memory: 1120kB
#include<stdio.h>
#include<string.h>
int main(){
int m,n,i,b,l,q,w,e,f,c,j;
char str[10];
char f1[10];
char f2[10];
char f3[10];
char f4[10];
int left[11];
int right[11];
scanf("%d%d",&n,&m);
strcpy(f1,"pushLeft");
strcpy(f2,"pushRight");
strcpy(f3,"popLeft");
strcpy(f4,"popRight");
l=0;
q=0;
w=0;
e=0;
f=0;
for(i=0;i<m;i++){
scanf("%s",str);
if(strcmp(str,f1)==0){
scanf("%d",&b);
if(l<n){
printf("Pushed in left: %d\n",b);
left[q]=b;
q++;
l++;
}
else
printf("The queue is full\n");
}
else if(strcmp(str,f2)==0){
scanf("%d",&b);
if(l<n){
printf("Pushed in right: %d\n",b);
right[w]=b;
w++;
l++;
}
else
printf("The queue is full\n");
}
else if(strcmp(str,f3)==0){
if(l>0){
q--;
if(q<0){
printf("Popped from left: %d\n",right[e]);
e++;
q=0;
}
else
printf("Popped from left: %d\n",left[q]);
l--;
}
else
printf("The queue is empty\n");
}
else if(strcmp(str,f4)==0){
if(l>0){
w--;
if(w<0){
printf("Popped from right: %d\n",left[f]);
f++;
w=0;
}
else
printf("Popped from right: %d\n",right[w]);
l--;
}
else
printf("The queue is empty\n");
}
if(l==0){
q=w=0;
e=f=0;
}
}
return 0;
}