Light OJ 1212 Double Ended Queue Solution

 


///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int test,t=1,n,m,number;
    cin>>test;
    while(test--)
    {
        printf("Case %d:\n",t++);
        cin>>n>>m;
        deque<int>q;
        string s;
        while(m--)
        {
            cin>>s;
            if(s=="pushLeft")
            {
                cin>>number;
                if(q.size()!=n)
                {
                    q.push_front(number);
                    cout<<"Pushed in left: "<<number<<endl;

                }
                else
                    cout<<"The queue is full"<<endl;
            }
            else if(s=="pushRight")
            {
                cin>>number;
                if(q.size()!=n)
                {
                    q.push_back(number);
                    cout<<"Pushed in right: "<<number<<endl;

                }
                else
                    cout<<"The queue is full"<<endl;
            }
            else if(s=="popLeft")
            {
                if(q.empty())cout<<"The queue is empty"<<endl;
                else
                {
                    cout<<"Popped from left: "<<q.front()<<endl;
                    q.pop_front();
                }
            }
            else if(s=="popRight")
            {
                if(q.empty())cout<<"The queue is empty"<<endl;
                else
                {
                    cout<<"Popped from right: "<<q.back()<<endl;
                    q.pop_back();
                }
            }
        }
    }
}

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.