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: 1120kB
Author: 2018212212225
In contest: 1284

#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int x=0;
	int b[21],l=0,r=0;
	while(m--){
		char a[60];
		int h;
		scanf("%s",a);
		if(!strcmp(a,"pushLeft")||!strcmp(a,"pushRight"))
			scanf("%d",&h);
		if(!strcmp(a,"pushLeft")&&x<n){
			x++;
			b[10-l]=h;
			l++;
			printf("Pushed in left: %d\n",h);
		}
		else if(!strcmp(a,"pushRight")&&x<n){
			x++;
			b[11+r]=h;
			r++;
			printf("Pushed in right: %d\n",h);
		}
		else if((!strcmp(a,"pushLeft")||!strcmp(a,"pushRight"))&&x==n){
			printf("The queue is full\n");
		}
		if(!strcmp(a,"popLeft")&&x>0){
			x--;
			l--;
			printf("Popped from left: %d\n",b[10-l]);
		}
		else if(!strcmp(a,"popRight")&&x>0){
			x--;
			r--;
			printf("Popped from right: %d\n",b[11+r]);
		}
		else if((!strcmp(a,"popRight")||!strcmp(a,"popLeft"))&&x==0){
			printf("The queue is empty\n");
		}
	}
}