poj 1028 Web Navigation

来源:互联网 发布:人员优化 编辑:程序博客网 时间:2024/05/17 05:57

链接:点击打开链接

对栈的运用。

#include<iostream> #include<stack> #include<string> #include<cstdio> #include<cstring> using namespace std; int main(){        stack<string>forward,backward;        int i,j;        string s,current="http://www.acm.org/";        while(getline(cin,s)){            if(s=="QUIT")            break;            if(s.size()>7){                backward.push(current);                current=s.substr(6);                cout<<current<<endl;                while(!forward.empty())                 forward.pop();                }             else if(s=="BACK"){                    if(backward.empty())                    cout<<"Ignored"<<endl;                    else{                        forward.push(current);                        current=backward.top();                        backward.pop();                        cout<<current<<endl;                        }                    }             else if(s=="FORWARD"){                    if(forward.empty())                    cout<<"Ignored"<<endl;                     else{                        backward.push(current);                        current=forward.top();                        forward.pop();                        cout<<current<<endl;                        }                    }                        }            return 0;        }