• 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;
    }
  • 相关阅读:
    android(eclipse)界面控件以及活动总结(二)
    android(eclipse)新手常见问题总结(一)
    易 忽略 知识 点
    switfmailer 邮件时间错误 处理
    error_log
    $_SERVER['URI']
    apache 服务器配置
    sock
    __autolaod
    delete CDU
  • 原文地址:https://www.cnblogs.com/rainydays/p/2820638.html
Copyright © 2020-2023  润新知