Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- int test;
- cin>>test;
- for(int t=1; t<=test; t++)
- {
- int m,n,x;
- cin>>m>>n;
- printf("Case %d:\n",t);
- deque<int>q;
- string s;
- while(n--)
- {
- cin>>s;
- if(s=="pushLeft" || s=="pushRight")
- {
- cin>>x;
- if(q.size()==m)
- printf("The queue is full\n");
- else
- {
- if(s=="pushLeft")
- {
- q.push_front(x);
- printf("Pushed in left: %d\n",x);
- }
- else
- {
- q.push_back(x);
- printf("Pushed in right: %d\n",x);
- }
- }
- }
- else
- {
- if(q.size()==0)
- {
- printf("The queue is empty\n");
- }
- else
- {
- if(s=="popLeft")
- {
- printf("Popped from left: %d\n",q.front());
- q.pop_front();
- }
- else
- {
- printf("Popped from right: %d\n",q.back());
- q.pop_back();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement