Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t,i;
- cin>>t;
- for(i=1;i<=t;i++)
- {
- int n,m,j,k,l,x,s,y;
- vector < pair<int,int> > v;
- deque <int> q;
- string st,sk;
- cin>>n>>m;
- j=0;
- l=m;
- while(l--)
- {
- cin>>st;
- if(st=="pushLeft")
- {
- cin>>x;
- j++;
- if(j>n)
- {
- j=n;
- v.push_back(make_pair(5,0));
- }
- else
- {
- q.push_front(x);
- v.push_back(make_pair(1,x));
- }
- }
- else if(st=="pushRight")
- {
- cin>>x;
- j++;
- if(j>n)
- {
- j=n;
- v.push_back(make_pair(5,0));
- }
- else
- {
- q.push_back(x);
- v.push_back(make_pair(2,x));
- }
- }
- else if(st=="popLeft")
- {
- j--;
- if(j<0)
- {
- j=0;
- v.push_back(make_pair(0,0));
- }
- else
- {
- x=q[0];
- q.pop_front();
- v.push_back(make_pair(3,x));
- }
- }
- else if(st=="popRight")
- {
- j--;
- if(j<0)
- {
- j=0;
- q.pop_back();
- v.push_back(make_pair(0,0));
- }
- else
- {
- x=q[q.size()-1];
- v.push_back(make_pair(4,x));
- }
- }
- }
- cout<<"Case "<<i<<":"<<endl;
- for(int k=0;k<m;k++)
- {
- if(v[k].first==0) cout<<"The queue is empty"<<endl;
- else if(v[k].first==5) cout<<"The queue is full"<<endl;
- else if(v[k].first==1) cout<<"Pushed in left: "<<v[k].second<<endl;
- else if(v[k].first==2) cout<<"Pushed in right: "<<v[k].second<<endl;
- else if(v[k].first==3) cout<<"Popped from left: "<<v[k].second<<endl;
- else if(v[k].first==4) cout<<"Popped from right: "<<v[k].second<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement