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: 2020kB
Author: 2017210904069
In contest: 1284

#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,m,x,p,q,count,i;
	int a[101];
	char str[30];
	scanf("%d %d",&n,&m);
	p = 49;q = 50;count = 0;
	for(i = 0;i<m;i++){
		scanf("%s",str);
		
		if(strcmp(str,"pushLeft")==0){
			scanf("%d",&x);
			if(count==n){
				printf("The queue is full\n");
			}
			else{
				a[p] = x;
				p--;
				count++;
				printf("Pushed in left: %d\n",x);
			}
		}
		
		if(strcmp(str,"pushRight")==0){
			scanf("%d",&x);
			if(count==n){
				printf("The queue is full\n");
			}
			else{
				a[q] = x;
				q++;
				count++;
				printf("Pushed in right: %d\n",x);	
			}
		}
		
		if(strcmp(str,"popLeft")==0){
			if(count==0){
				printf("The queue is empty\n");
			}
			else{
				p++;
				printf("Popped from left: %d\n",a[p]);
				count--;	
			}
		}
		
		if(strcmp(str,"popRight")==0){
			if(count==0){
				printf("The queue is empty\n");
			}
			
			else{
				q--;
				printf("Popped from right: %d\n",a[q]);
				count--;
			}
		}
	}
}