poj 1028 Web Navigation(模拟)「建议收藏」

poj 1028 Web Navigation(模拟)

大家好,又见面了,我是全栈君。

题目链接:http://poj.org/problem?

id=1028

Description

Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem, you are asked to implement this. 

The following commands need to be supported: 

BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored. 

FORWARD: Push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If the forward stack is empty, the command is ignored. 

VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied. 

QUIT: Quit the browser. 

Assume that the browser initially loads the web page at the URL http://www.acm.org/

Input

Input is a sequence of commands. The command keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. URLs have no whitespace and have at most 70 characters. You may assume that no problem instance requires more than 100 elements in each stack at any time. The end of input is indicated by the QUIT command.

Output

For each command other than QUIT, print the URL of the current page after the command is executed if the command is not ignored. Otherwise, print “Ignored”. The output for each command should be printed on its own line. No output is produced for the QUIT command.

Sample Input

VISIT http://acm.ashland.edu/
VISIT http://acm.baylor.edu/acmicpc/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT

Sample Output

http://acm.ashland.edu/
http://acm.baylor.edu/acmicpc/
http://acm.ashland.edu/
http://www.acm.org/
Ignored
http://acm.ashland.edu/
http://www.ibm.com/
http://acm.ashland.edu/
http://www.acm.org/
http://acm.ashland.edu/
http://www.ibm.com/
Ignored

Source

题意:

模拟浏览器浏览网页是前后翻页。

思路:

开两个栈。分别存储当前网页前后的网页,注意新訪问一个网页时,应该把当前网页的前面的栈清空!

代码例如以下:

#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
stack <string>b;
stack <string>f;
int main()
{
    string tt = "http://www.acm.org/";
    string s;
    while(cin >> s)
    {
        if(s == "QUIT")
            break;
        if(s == "VISIT")
        {
            b.push(tt);
            cin >> tt;
            cout<<tt<<endl;//始终输出当前页
            while(!f.empty())//当新訪问一个页面的时候把之前页面前面的清空
            {
                f.pop();
            }
        }
        else if(s == "BACK")
        {
            if(!b.empty())
            {
                f.push(tt);
                tt = b.top();
                b.pop();
                cout<<tt<<endl;//始终输出当前页
            }
            else
                cout<<"Ignored"<<endl;
        }
        else
        {
            if(!f.empty())
            {
                b.push(tt);
                tt = f.top();
                f.pop();
                cout<<tt<<endl;//始终输出当前页
            }
            else
                cout<<"Ignored"<<endl;
        }
    }
    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115330.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 八路抢答器一个数码管C语言,八路抢答器设计 – 八路抢答器电路设计方案汇总(五款模拟电路设计原理及工作原理详细)…「建议收藏」

    八路抢答器一个数码管C语言,八路抢答器设计 – 八路抢答器电路设计方案汇总(五款模拟电路设计原理及工作原理详细)…「建议收藏」八路抢答器电路设计方案四:一个简单的的八路抢答器电路详细电路设计方案:八路抢答器电路图八路抢答器电路设计方案五:基于74LS148和74LS297的八路抢答器设计要求与内容在许多比赛活动中,为了准确、公正、直观地判断出第一抢答者,通常设置一台抢答器,通过数显、灯光或音响等多种手段指示出第一抢答者。(1)设计制作一个可容纳8组参赛的数字式抢答器,每组设置一个抢答按钮供抢答者使用。(2)电路具有第一抢…

    2022年10月20日
    1
  • 去除限制 Post 请求大小限制

    去除限制 Post 请求大小限制tomcat6及以下版本 在tomcat文件夹下的conf文件中的server.xml配置中添加: maxPostSize=”0″//0表示不限制大小。tomcat7及以上版本​ 在tomcat文件夹下的conf文件中的server.xml配置中添加:​ maxPostSize=”-1″//-1表示不限制大小。​ maxPostSiz…

    2022年7月18日
    18
  • android之存储篇_存储方式总览

    作为一个完成的应用程序,数据存储操作是必不可少的。因此,Android系统一共提供了四种数据存储方式。分别是:SharePreference、SQLite、Content Provider和File。由于Android系统中,数据基本都是私有的的,都是存放于“data/data/程序包名”目录下,所以要实现数据共享,正确方式是使用Content Provider。  SQLite: SQLit

    2022年3月10日
    43
  • meta标签设置用极速模式打开网页

    meta标签设置用极速模式打开网页1浏览器集成了多种浏览器内核,需要强制使用极速模式<metaname=”renderer”content=”webkit”/>2meta标签中X-UA-Compatible属性的使用的极速模式<metahttp-equiv=”X-UA-Compatible”content=”IE=edge,chrome=1″/>…

    2025年6月13日
    4
  • MATLAB中向量_向量法表示字符串

    MATLAB中向量_向量法表示字符串Matlab中的向量和数组(超详细)文章目录Matlab中的向量和数组(超详细)Matlab中的向量介绍创建向量向量的大小索引向量数值索引逻辑索引缩短向量向量运算算术运算逻辑运算sum()、min()、max()、round()、ceil()、floor()、fix()切片Maltab中的数组数组的属性创建数组访问数组元素数组运算数组的算术运算数组的逻辑运算sum()、max()、min()、……

    2025年7月2日
    2
  • arcgis python实例_arcgis二次开发_arcgis二次开发python_arcgis二次开发实例

    arcgis python实例_arcgis二次开发_arcgis二次开发python_arcgis二次开发实例[1.rar]-QQ连连看的源码.单消秒杀挂机等功能喜欢的朋友请拿去研究[qqCHAR.rar]-qq验证码识别程序可以叫准确的识别出qq登陆前的验证码[1.rar]-本书以Visualc++作为开发语言,结合大量实例,详细介绍了利用Arcobjects组件进行GIS二次开发的方法和过程。书中在讲述利用Arcobjects实现GIS功能的基础上,重点介绍了在Arcobjects环境…

    2022年6月17日
    25

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号