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

#include<iostream>
#include<algorithm>
#include<cmath>
#include<deque>
using namespace std;

int main()
{
	int n,m;
	cin >> n >> m;
	deque<int> d1;
	while(m--)
	{
		string tmp;
		int x;
		cin >> tmp;
		if (tmp=="pushLeft")
		{
			cin >> x;
			if (d1.size()>=n)
				cout << "The queue is full" << endl;
			else
			{
				d1.push_front(x);
				cout << "Pushed in left: " << x << endl;
			}
		}
		else if (tmp=="pushRight")
		{
			cin >> x;
			if (d1.size()>=n)
				cout << "The queue is full"<< endl;
			else
			{
				d1.push_back(x);
				cout << "Pushed in right: " << x << endl;
			}
		}	
		else if (tmp=="popLeft")
		{
			if (d1.empty())
				cout << "The queue is empty" << endl;
			else
			{
				int num=d1.front();
				d1.pop_front();
				cout << "Popped from left: " << num << endl;
			}
		}
		else if (tmp=="popRight")
		{
			if (d1.empty())
				cout << "The queue is empty" << endl;
			else
			{
				int num=d1.back();
				d1.pop_back();
				cout << "Popped from right: " << num << endl;
			}
		}
	}
}