Result: Accepted
Time: 3ms
Memory: 1124kB
#include<stdio.h>
#include<string.h>
#include<math.h>
int isPrime(int x);
#define A 30
int main()
{
int n,m;
scanf("%d %d",&n,&m);
getchar();
int left=15;
int right=16;
int x=0;
int c[30];
while(m--)
{
int num=0;
char words[A];
gets(words);
if(x==n&&words[4]!='e'&&words[4]!='i')
{
printf("The queue is full\n");
continue;
}
if(x==0&&words[4]!='L'&&words[4]!='R')
{
printf("The queue is empty\n");
continue;
}
int j=1;
for(int i=strlen(words)-1;;i--)
{
if(words[i]==' ')
break;
num+=(words[i]-48)*j;
j*=10;
}
if(words[4]=='L')
{
x++;
c[left]=num;
left--;
printf("Pushed in left: %d\n",num);
continue;
}
if(words[4]=='R')
{
x++;
c[right]=num;
right++;
printf("Pushed in right: %d\n",num);
continue;
}
if(words[4]=='e')
{
x--;
left++;
printf("Popped from left: %d\n",c[left]);
continue;
}
if(words[4]=='i')
{
x--;
right--;
printf("Popped from right: %d\n",c[right]);
continue;
}
}
return 0;
}