美文网首页
poj1028 STL_stack

poj1028 STL_stack

作者: 暖昼氤氲 | 来源:发表于2019-11-01 17:38 被阅读0次
/*
Time:2019.11.1
Author: Goven
type:网页模拟:Stack应用 
err:
ref:
*/
#include<iostream>
#include<stack>
#include<string>
using namespace std;

int main()
{
    stack<string> fore, back;
    string act, web = "http://www.acm.org/";
    while (cin >> act) {
        if (act == "VISIT") {
            back.push(web);
            while (!fore.empty()) fore.pop();
            cin >> web;
            cout << web << endl;
        }
        else if (act == "BACK") {
            if (back.empty())
                cout << "Ignored" << endl;
            else {
                fore.push(web);
                web = back.top();
                back.pop();
                cout << web << endl;
            }
            
        }
        else if (act == "FORWARD"){
            if (fore.empty())
                cout << "Ignored" << endl;
            else {
                back.push(web);
                web = fore.top();
                fore.pop();
                cout << web << endl;
            }
        } 
        else if (act == "QUIT")
            break;
    }
    return 0;
}


相关文章

网友评论

      本文标题:poj1028 STL_stack

      本文链接:https://www.haomeiwen.com/subject/vylqbctx.html