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: 4ms
Memory: 1756kB
Author: 2017212212174
In contest: 1284

#include<iostream>
#include<string.h>

using namespace std;

struct xixi{
	int left;
	int n;
	int right;
};



int main(){
	struct xixi p[105];
    for(int i=0;i<101;i++)p[i].n=i;
	int n,M;
	scanf("%d%d",&n,&M);
	
	int date=0,x,lll,rrr;
	char ccc[10];
	while(M--){
		scanf("%s",&ccc);
		if(strcmp(ccc,"pushLeft")==0){
			scanf("%d",&x);
			if(date==0){
				p[x].left=x;lll=x;
				p[x].right=x;rrr=x;
				printf("Pushed in left: %d",x);
				date++;
			}
			else if(date==n)printf("The queue is full"); 
			else {
				p[lll].left=x;
				p[x].left=x;
				p[x].right=lll;lll=x;
				printf("Pushed in left: %d",x);
				date++;
			}
			
		}
		else if(strcmp(ccc,"pushRight")==0){
			scanf("%d",&x);
			if(date==0){
				p[x].left=x;lll=x;
				p[x].right=x;rrr=x;
				printf("Pushed in right: %d",x);
				date++;
			} 
			else if(date==n)printf("The queue is full"); 
			else {
				p[rrr].right=x;
				p[x].right=x;
				p[x].left=rrr;rrr=x;
				printf("Pushed in right: %d",x);
				date++;
			}
		}
		else if(strcmp(ccc,"popLeft")==0){
			if(date==0)printf("The queue is empty");
			else if(date==1){
				printf("Popped from left: %d",lll);
				date--;
			}
			else{
				int ooo=p[lll].right;
				printf("Popped from left: %d",lll);
				p[ooo].left=ooo;lll=ooo;
				date--;
			}
		}
		else if(strcmp(ccc,"popRight")==0){
			if(date==0)printf("The queue is empty");
			else if(date==1){
				printf("Popped from right: %d",rrr);
				date--;
			}
			else{
				int ooo=p[rrr].left;
				printf("Popped from right: %d",rrr);
				p[ooo].right=ooo;rrr=ooo;
				date--;
			}
		}
		printf("\n");
	}
	
	return 0;
}