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

#include<iostream>
#include<string>
#include<deque>
using namespace std;
deque<int>dq;
int main() 
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) 
	{
		string str;
		int id;
		cin >> str;
		if (str == "pushLeft" || str == "pushRight") 
		{
			cin >> id;
			if (dq.size() >= N)
				cout << "The queue is full" << endl;
			else 
			{
				if (str == "pushLeft")
				{
					dq.push_front(id);
					cout << "Pushed in left: " << id << endl;
				}
				if (str == "pushRight")
				{
					dq.push_back(id);
					cout << "Pushed in right: " << id << endl;
				}
			}
		}
		if (str == "popLeft" || str == "popRight") 
		{
			if (dq.size() == 0)
				cout << "The queue is empty" << endl;
			else 
			{
				if (str == "popLeft") 
				{
					int tmp = dq.front();
					dq.pop_front();
					cout << "Popped from left: " << tmp << endl;
				}
				if (str == "popRight")
				{
					int tmp = dq.back();
					dq.pop_back();
					cout << "Popped from right: " << tmp << endl;
				}
			}
		}
	}
	return 0;
}