Result: Accepted
Time: 3ms
Memory: 1756kB
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
using namespace std;
int b,c,t,m,n,flag,cnt,temp,temp1,temp2;
const int maxn=22;
char a[12];
int num[maxn];
int main(){
scanf("%d %d",&n,&m);
temp=11;
temp1=temp,temp2=temp+1;
for(int i=0;i<m;i++){
scanf("%s",a);
getchar();
if(strcmp(a,"pushLeft")==0){
scanf("%d",&b);
cnt=0;
for(int i=0;i<22;i++){
if(num[i]!=0)
cnt++;
}
if(cnt<n){
num[temp1--]=b;
printf("Pushed in left: %d\n",b);
}
else printf("The queue is full\n");
}
else if(strcmp(a,"pushRight")==0){
scanf("%d",&b);
cnt=0;
for(int i=0;i<22;i++){
if(num[i]!=0)
cnt++;
}
if(cnt<n){
num[temp2++]=b;
printf("Pushed in right: %d\n",b);
}
else printf("The queue is full\n");
}
else if(strcmp(a,"popLeft")==0){
cnt=0;
for(int i=0;i<22;i++){
if(num[i]!=0)
cnt++;
}
if(cnt>0){
printf("Popped from left: %d\n",num[++temp1]);
num[temp1--]=0;
temp1+=1;
}
else printf("The queue is empty\n");
}
else{
cnt=0;
for(int i=0;i<22;i++){
if(num[i]!=0)
cnt++;
}
if(cnt>0){
printf("Popped from right: %d\n",num[--temp2]);
num[temp2++]=0;
temp2-=1;
}
else printf("The queue is empty\n");
}
}
return 0;
}