Lightoj LOJ-1113 Discover the Web (basic stack problem)




Problem :      Discover the web

Solution in c++:

///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 t,n,i=1;
    cin>>t;
    while(t--)
    {
        printf("Case %d:\n",i++);
        string s,a,b,v,temp;
        stack<string>s1;
        stack<string>s2;
        v="http://www.lightoj.com/";
        s1.push(v);
        while(cin>>a)
        {
            if(a=="QUIT")
                break;
            if(a=="VISIT")
            {
                cin>>b;
                cout<<b<<endl;
                s1.push(b);
                if(!s2.empty())
                {
                    while(!s2.empty())
                    {
                        s2.pop();
                    }
                }
            }
            else
            {
                if(a=="BACK")
                {
                    temp=s1.top();
                    s2.push(temp);
                    s1.pop();
                    if(!s1.empty())
                        cout<<s1.top()<<endl;
                    else
                    {
                        cout<<"Ignored"<<endl;
                        temp=s2.top();
                        s1.push(temp);
                        s2.pop();
                    }

                }
                else if(a=="FORWARD")
                {
                    if(s2.size()==0)
                        cout<<"Ignored"<<endl;
                    else
                    {
                        if(!s2.empty())
                        {
                            cout<<s2.top()<<endl;
                            temp=s2.top();
                            s1.push(temp);
                            s2.pop();
                        }
                    }
                }

            }

        }

    }
}


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.