zoukankan      html  css  js  c++  java
  • POJ 1028解答

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <stack>
    #include <string>

    using namespace std;

    int main()
    {
    char command[16];
    char url[71];

    stack<string> forwardStack;
    stack<string> backStack;

    string curUrl = "http://www.acm.org/";
    backStack.push(curUrl);

    while (true)
    {
    gets_s(command);

    if (strcmp(command, "QUIT") == 0)
    {
    break;
    }
    else if (strcmp(command, "VISIT") == 0)
    {
    gets_s(url);
    curUrl = url;
    backStack.push(curUrl);

    puts(curUrl.c_str());
    puts("\n");
    }
    else if (strcmp(command, "BACK") == 0)
    {
    if (backStack.empty())
    {
    puts("Ignored\n");
    }
    else
    {
    forwardStack.push(curUrl);
    backStack.pop();
    if (!backStack.empty())
    {
    curUrl = backStack.top();
    puts(curUrl.c_str());
    puts("\n");
    }
    else
    {
    puts("Ignored\n");
    }

    }

    }
    else if (strcmp(command, "FORWARD") == 0)
    {
    if (forwardStack.empty())
    {
    puts("Ignored\n");
    }
    else
    {
    backStack.push(curUrl);
    forwardStack.pop();
    if (!forwardStack.empty())
    {
    curUrl = forwardStack.top();
    puts(curUrl.c_str());
    puts("\n");
    }
    else
    {
    puts("Ignored\n");
    }

    }

    }


    }

    }

  • 相关阅读:
    web 开发之酷炫--- 酷炫展示
    攻城狮的体检
    科技发烧友之智能路由
    科技发烧友之3d吉米投影
    科技发烧友之单反佳能700d中高端
    上海
    视频会议
    机器学习之信息
    filter
    centos 20T硬盘(超过16T)分区
  • 原文地址:https://www.cnblogs.com/guochen/p/5382360.html
Copyright © 2011-2022 走看看