Result: Accepted
Time: 4ms
Memory: 1124kB
#include<stdio.h>
#include<math.h>
#include<string.h>
int x[1000];
char str[1000];
int main() {
int l,m,n,i,j,temp,ans,cd,fang;
scanf("%d %d",&n,&m);
for (i=0; i<n; i++) {
x[i]=0;
}
cd=0;
while (m--) {
scanf("%s",str);
if (strcmp(str,"popLeft")==0) {
if (cd==0)
printf("The queue is empty\n");
else {
printf("Popped from left: %d\n",x[0]);
for (i=0; i<cd; i++) {
x[i]=x[i+1];
}
x[cd-1]=0;
cd--;
}
} else if (strcmp(str,"popRight")==0) {
if (cd==0)
printf("The queue is empty\n");
else {
printf("Popped from right: %d\n",x[cd-1]);
x[cd-1]=0;
cd--;
}
} else if (strcmp(str,"pushLeft")==0) {
scanf("%d",&fang);
if (cd==n) {
printf("The queue is full\n");
} else {
for (i=cd; i>0; i--) {
x[i]=x[i-1];
}
x[0]=fang;
cd++;
printf("Pushed in left: %d\n",fang);
}
} else if (strcmp(str,"pushRight")==0) {
scanf("%d",&fang);
if (cd==n) {
printf("The queue is full\n");
} else {
x[cd]=fang;
cd++;
printf("Pushed in right: %d\n",fang);
}
}
}
}