Result: Accepted
Time: 4ms
Memory: 1756kB
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<deque>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<string>
using namespace std;
struct m {
string name;
int num;
};
deque<int>a;
bool cmp1 (int x, int y) {
return x < y;
}
bool cmp (m x, m y) {
return x.num > y.num;
}
int main() {
int t, i, j;
int n, m;
cin >> n >> m;
while(m--) {
string a1;
int a2;
cin >> a1;
if(a1 == "pushLeft") {
if(a.size() < n) {
cin >> a2;
a.push_front(a2);
cout << "Pushed in left: " << a2;
}
else {
cin >> a2;
cout << "The queue is full";
}
}
else if(a1 == "pushRight") {
if(a.size() < n) {
cin >> a2;
a.push_back(a2);
cout << "Pushed in right: " << a2;
}
else {
cin >> a2;
cout << "The queue is full";
}
}
else if(a1 == "popLeft") {
if(!a.empty()) {
cout << "Popped from left: " << a[0];
a.pop_front();
}
else {
cout << "The queue is empty";
}
}
else {
if(!a.empty()) {
cout << "Popped from right: " << a[a.size() - 1];
a.pop_back();
}
else {
cout << "The queue is empty";
}
}
if(m != 0)
cout << endl;
}
return 0;
}