Result: Accepted
Time: 3ms
Memory: 1124kB
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(){
int n,m,i,x[55]={0},y,count=0,x1=50,y1=51,l[100]={0};
char a[55][20];
scanf("%d %d",&n,&m);
getchar();
for(i=0;i<m;i++){
gets(a[i]);
y=strlen(a[i]);
if((int)(a[i][y-1])>=48&&(int)(a[i][y-1])<=57&&((int)(a[i][y-2])<48||(int)(a[i][y-2])>57))
x[i]=(int)(a[i][y-1])-48;
else if((int)(a[i][y-1])>=48&&(int)(a[i][y-1])<=57&&((int)(a[i][y-2])>=48&&(int)(a[i][y-2])<=57))
x[i]=(int)(a[i][y-1])-48+((int)(a[i][y-2])-48)*10;
}
for(i=0;i<m;i++){
if(a[i][4]==76){
if(count>=n)
printf("The queue is full\n");
else{
count++;
l[x1]=x[i];
printf("Pushed in left: %d\n",x[i]);
x1--;
}
}
if(a[i][4]==82){
if(count>=n)
printf("The queue is full\n");
else{
count++;
l[y1]=x[i];
printf("Pushed in right: %d\n",x[i]);
y1++;
}
}
if(a[i][3]==76){
if(count<=0)
printf("The queue is empty\n");
else{
count--;
printf("Popped from left: %d\n",l[x1+1]);
x1++;
}
}
if(a[i][3]==82){
if(count<=0)
printf("The queue is empty\n");
else{
printf("Popped from right: %d\n",l[y1-1]);
y1--;
count--;
}
}
}
}