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: 2018212212048
In contest: 1284

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
//左边界 i, 左边空
//右边界 j,当前空 
int main(){
	int a[200];
	memset(a,0,sizeof a);
	int i=100;
	int j=100;
	int cnt=0;
	int n,m;
	string op;
	int mark;
	cin>>n>>m;
	getchar();
	while(m--){
		cin>>op;
		getchar();
		if(op=="pushLeft"){
			scanf("%d",&mark);
			if(cnt==n) printf("The queue is full\n");
			else{
				getchar();
				i--;
				a[i]=mark;
				cnt++;
				printf("Pushed in left: %d\n",mark);
			}
			
		}
		else if(op=="pushRight"){
			scanf("%d",&mark);
			if(cnt==n) printf("The queue is full\n");
			else{
				getchar();
				a[j]=mark;
				j++;
				cnt++;
				printf("Pushed in right: %d\n",mark);	
			}
		}
		else if(op=="popLeft"){
			if(cnt==0) printf("The queue is empty\n");
			else{
				mark=a[i];
				i++;
				cnt--;
				printf("Popped from left: %d\n",mark);
			}
		}
		else if(op=="popRight"){
			if(cnt==0) printf("The queue is empty\n");
			else{
				mark=a[j-1];
				j--;
				cnt--;
				printf("Popped from right: %d\n",mark);
			}
		}
	}
}