Result: Accepted
Time: 6ms
Memory: 2020kB
#include<bits/stdc++.h>
using namespace std;
int box[20];
int k = 0;
void PushLeft(int x)
{
for(int i = k;i > 0;--i)
box[i] = box[i-1];
box[0] = x;
k++;
}
void PushRight(int x)
{
box[k] = x;
k++;
}
int PopLeft()
{
int p = box[0];
k--;
for(int i = 0;i < k;++i)
{
box[i] = box[i+1];
}
return p;
}
int PopRight()
{
k--;
return box[k];
}
int main()
{
int n,m;
scanf("%d %d",&n,&m);
char cz[20];
k = 0;
while(m--)
{
scanf("%s",&cz);
if(cz[1] == 'u')
{
int pu;
scanf("%d",&pu);
if(k == n)
printf("The queue is full\n");
else
{
if(cz[4] == 'L')
{
PushLeft(pu);
printf("Pushed in left: %d\n",pu);
}
else
{
PushRight(pu);
printf("Pushed in right: %d\n",pu);
}
}
}
else
{
if(k == 0)
printf("The queue is empty\n");
else
{
if(cz[3] == 'L')
{
printf("Popped from left: %d\n",PopLeft());
}
else
{
printf("Popped from right: %d\n",PopRight());
}
}
}
}
return 0;
}