Result: Accepted
Time: 6ms
Memory: 1120kB
#include<stdio.h>
#include<string.h>
int main(){
int s;
int n,m;
int i;
int a=12;
int b=13;
int c=0;
int x[25];
char str[15];
for(i=0;i<=24;i++) x[i]=-1;
scanf("%d %d",&n,&m);
for(i=1;i<=m;i++){
scanf("%s",str);
if(strcmp(str,"pushLeft")==0){
scanf("%d",&s);
c++;
if(c>n){
printf("The queue is full");
if(i!=m) printf("\n");
c--;
}
else{
x[a]=s;
printf("Pushed in left: %d",x[a]);
if(i!=m) printf("\n");
a--;
}
}
else if(strcmp(str,"pushRight")==0){
scanf("%d",&s);
c++;
if(c>n){
printf("The queue is full");
if(i!=m) printf("\n");
c--;
}
else{
x[b]=s;
printf("Pushed in right: %d",x[b]);
if(i!=m) printf("\n");
b++;
}
}
else if(strcmp(str,"popLeft")==0){
c--;
if(c<0){
printf("The queue is empty");
c++;
if(i!=m) printf("\n");
}
else{
a++;
printf("Popped from left: %d",x[a]);
if(i!=m) printf("\n");
x[a]=-1;
}
}
else if(strcmp(str,"popRight")==0){
c--;
if(c<0){
printf("The queue is empty");
c++;
if(i!=m) printf("\n");
}
else{
b--;
printf("Popped from right: %d",x[b]);
if(i!=m) printf("\n");
x[b]=-1;
}
}
}
}