zoukankan      html  css  js  c++  java
  • poj1028

    简单栈模拟

    View Code
    #include <iostream>
    #include <stack>
    #include <string>
    using namespace std;
    
    stack<string>bstack, fstack;
    string    current;
    
    void visit()
    {
        if (current != "")
            bstack.push(current);
        cin >> current;
        while (!fstack.empty())
            fstack.pop();
        cout << current << endl;
    }
    
    void forward()
    {
        if (fstack.empty())
        {
            printf("Ignored\n");
            return;
        }
        bstack.push(current);
        current = fstack.top();
        fstack.pop();
        cout << current << endl;
    }
    
    void back()
    {
        if (bstack.empty())
        {
            printf("Ignored\n");
            return;
        }
        fstack.push(current);
        current = bstack.top();
        bstack.pop();
        cout << current << endl;
    }
    
    int main()
    {
        string    command;
    
        //freopen("t.txt", "r", stdin);
        current = "http://www.acm.org/";
        while (cin >> command && command != "QUIT")
        {
            if (command == "VISIT")
                visit();
            else if (command == "FORWARD")
                forward();
            else if (command == "BACK")
                back();
            getchar();
        }
        return 0;
    }
  • 相关阅读:
    wx.Notebook
    wx.button
    wxpython wx.windows的API
    wxpython Menus and toolbars
    使用 profile 进行python代码性能分析
    html 表格边框的设置
    Java IO方式
    Java文件拷贝方式
    S.O.L.I.D原则
    面向对象设计
  • 原文地址:https://www.cnblogs.com/rainydays/p/2820638.html
Copyright © 2011-2022 走看看