ZOJ1061

来源:互联网 发布:html怎么调用php文件 编辑:程序博客网 时间:2024/05/18 20:35

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=61

用容器stack,剩下的就是模拟了。

#include<iostream>#include<stack>#include<string>using namespace std;stack<string> Front; //前进栈stack<string> Back;  //后退栈string URL;  //当前页void BACK(string order){    if (Back.empty())    {        cout<<"Ignored"<<endl;        return;    }    order = order.erase(0,4);    Front.push(URL);    URL = Back.top();    Back.pop();    cout<<URL<<endl;}void FORWARD(string order){    if (Front.empty())    {        cout<<"Ignored"<<endl;        return;    }    order = order.erase(0,7);    Back.push(URL);    URL = Front.top();    Front.pop();    cout<<URL<<endl;}void VISIT(string order){    order = order.erase(0,6);    Back.push(URL);    URL = order;    cout<<URL<<endl;    while (!Front.empty()) Front.pop();}int main(){    int N;    cin>>N;    while (N--)    {        string order;        bool Exit = false;        URL = "http://www.acm.org/";        while (getline(cin,order) && order!="QUIT")        {            switch (order[0])            {                case 'B':BACK(order);break;                case 'F':FORWARD(order);break;                case 'V':VISIT(order);break;            }        }        while (!Front.empty()) Front.pop();        while (!Back.empty()) Back.pop();        if (N)        {            cin.ignore();            cout<<endl;        }    }    return 0;}


0 0
原创粉丝点击