Result: Accepted
Time: 4ms
Memory: 1756kB
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
struct my
{
int start;
int end;
int sz[1000];
};
int main()
{
int N,M;
cin>>N>>M;int sum=0;
my a;
a.end=50;
a.start=51;
for(int i=1;i<=M;i++)
{
char s[20];
scanf("%s",s);
if(strcmp(s,"pushLeft")==0)
{
int x;
scanf("%d",&x);
if(sum+1>N)
printf("The queue is full\n");
else
{
printf("Pushed in left: %d\n",x);
a.start--;
a.sz[a.start]=x;
sum++;
}
}
else if(strcmp(s,"pushRight")==0)
{
int x;
scanf("%d",&x);
if(sum+1>N)
printf("The queue is full\n");
else
{
a.end++;
a.sz[a.end]=x;
printf("Pushed in right: %d\n",x);
sum++;
}
}
else if(strcmp(s,"popLeft")==0)
{
if(sum-1<0)
printf("The queue is empty\n");
else
{
printf("Popped from left: %d\n",a.sz[a.start]);
a.start++;
sum--;
}
}
else if(strcmp(s,"popRight")==0)
{
if(sum-1<0)
printf("The queue is empty\n");
else
{
printf("Popped from right: %d\n",a.sz[a.end]);
a.end--;
sum--;
}
}
}
return 0;
}