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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.