Start: Jul, 10, 2019 08:30:00
2019年度暑期短学期达标测试补考
End: Jul, 10, 2019 11:30:00
Time elapsed:
Time remaining:

Problem_ID: I
Result: Accepted
Time: 3ms
Memory: 1756kB
Author: 2018212212163
In contest: 1284

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
int n,m;
int main()
{
	int zuo[20],you[20],num=0,x=0,y=0,w;
	char step[20];
	scanf("%d %d",&n,&m);
	while(m--){
		scanf("%s",step);
		if(strcmp(step,"pushLeft")==0){
			scanf("%d",&w);
			if(num==n) printf("The queue is full\n");
			else{
				num++;
				zuo[++x]=w;
				printf("Pushed in left: %d\n",w);
			}
		}else if(strcmp(step,"pushRight")==0){
			scanf("%d",&w);
			if(num==n) printf("The queue is full\n");
			else{
				num++;
				you[++y]=w;
				printf("Pushed in right: %d\n",w);
			}
		}else if(strcmp(step,"popLeft")==0){
			if(num==0) printf("The queue is empty\n");
			else{
				num--;
				if(x>0) printf("Popped from left: %d\n",zuo[x]),x--;
				else{
					printf("Popped from left: %d\n",you[1]);
					for(int i=2;i<=y;i++) you[i-1]=you[i];
					y--;
				} 
			}
		}else if(strcmp(step,"popRight")==0){
			if(num==0) printf("The queue is empty\n");
			else{
				num--;
				if(y>0) printf("Popped from right: %d\n",you[y]),y--;
				else{
					printf("Popped from right: %d\n",zuo[1]);
					for(int i=2;i<=x;i++) zuo[i-1]=zuo[i];
					x--;
				} 
			}
		}
	}
}