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: 6ms
Memory: 1760kB
Author: 2018212212122
In contest: 1284

#include <cstdio>
#include <iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<deque>
using namespace std;
int n,m,i,j,k;
int main()
{
	scanf("%d %d",&n,&m);
	char s[114];
	deque<int>q;
	while(m--){
		scanf("%s %d",s,&k);
		if((!strcmp("pushLeft",s)||(!strcmp("pushRight",s))))
		{
			if(q.size()==n)
				puts("The queue is full");
			else
			{
				if(!strcmp("pushLeft",s)){
					q.push_back(k);
				printf("Pushed in left: %d\n",k);
				}
				if(!strcmp("pushRight",s)){
					q.push_front(k);
					printf("Pushed in right: %d\n",k);
				}
			}
		}
		if((!strcmp("popLeft",s)||(!strcmp("popRight",s)))){
			if(q.size()==0)
				puts("The queue is empty");
			else
			{
				if(!strcmp("popLeft",s)){
					printf("Popped from left: %d\n",q.back());
					q.pop_back();
				}
				if(!strcmp("popRight",s)){
					printf("Popped from right: %d\n",q.front());
					q.pop_front();
				}
			}
		}
	}
	return 0;
}