poj1028 STL_stack

2019-11-01  本文已影响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;
}


上一篇下一篇

猜你喜欢

热点阅读