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 Code

 Problem:         User:
Memory: 200K Time: 0MS
Language: C++ Result: Accepted
Source Code
#include"iostream"
#include"cstring"
#include"string"
#include"stack"
using namespace std;
int main()
{
stack<string> s1,s2;
string s,ss;
s="http://www.acm.org/";
s1.push(s);
while(cin>>s)
{
if(s=="QUIT")
break;
if(s=="VISIT")
{
cin>>ss;
cout<<ss<<endl;
s1.push(ss);
while(!s2.empty())
s2.pop();
}
else if(s=="BACK")
{
//cout<<"back "<<s1.size()<<endl;
if(s1.size()>=)
{
s2.push(s1.top());
s1.pop();
cout<<s1.top()<<endl;
}
else
cout<<"Ignored"<<endl;
}
else if(s=="FORWARD")
{
if(!s2.empty())
{
cout<<s2.top()<<endl;
s1.push(s2.top());
s2.pop();
}
else
cout<<"Ignored"<<endl;
}
}
return ;
}

Web Navigation的更多相关文章

  1. poj 1028 Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31088   Accepted: 13933 ...

  2. POJ1028 Web Navigation

    题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...

  3. POJ 1028:Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30828   Accepted: 13821 ...

  4. POJ-1028 Web Navigation 和TOJ 1196. Web Navigation

    Standard web browsers contain features to move backward and forward among the pages recently visited ...

  5. [POJ1028]Web Navigation(栈)

    这题是01年East Central North的A题,目测是签到题 Description Standard web browsers contain features to move backwa ...

  6. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  7. poj 1208 Web Navigation(堆栈操作)

    一.Description Standard web browsers contain features to move backward and forward among the pages re ...

  8. ZOJ 1061 Web Navigation

    原题链接 题目大意:模拟一个浏览器,打开一个网页.后退或者前进,输出网址. 解法:用两个堆栈分别表示后退保存的网页和前进保存的网页.初始化时把当前页面压入后退堆栈的栈顶.要注意几点,一个是每次记得要清 ...

  9. POJ 1028 Web Navigation 题解

    考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...

随机推荐

  1. [转]sublime 使用技巧总结

    原文链接:http://www.cnblogs.com/yingzi/archive/2012/04/24/2469056.html 对于用惯了editplus的人来说,突然接触到sublime有点无 ...

  2. AspNetPager 的使用

    下面选用的是新闻发布系统里用的代码. SQL 存储过程: CREATE PROCEDURE procNewsSelectByPager @startRecordIndex int, @endRecor ...

  3. java 图像分析与处理库

    OpenCv4Android: http://opencv.org/platforms/android.html opencv官方中文文档: http://www.opencv.org.cn/open ...

  4. Cocos2dx游戏源码合集(BY懒骨头+持续更新+2014.02.21)

    转自:http://blog.csdn.net/iamlazybone/article/details/19612941 声明: <萝莉快跑><喵汪大战>两个demo的原作者b ...

  5. HTML+CSS+JS学习总结

    HTML: 什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 不是一种编程语言,而是一种标记 ...

  6. LINUX如何查看其他用户的操作

    我们知道可以使用history命令,查看自己的操作记录,但如果你是root用户,如何查看其它用户的操作记录呢?   其实history命令只是把当前用户目录下的~/.bash_History文件内容列 ...

  7. centos 使用mutt 命令发送邮件,随笔非教程

    #按照mutt yum -y install mutt #发送邮件 echo .com -s "邮件主题" -a 附件本地地址

  8. 使用https时,网站一些内容不能正常显示的问题

    在网站开发过程中,使用http网站页面一切正常. 但改成https后,发现网站一些页面不能正常显示出来,比如看上去没有样式等. 原因是: 在程序中调用了比如JQuery,而引用的URL使用的是Http ...

  9. UVaLive 7370 Classy (排序,比较)

    题意:给定 n 个人,和他们的数进行比较,从后面开始比,如果不够长,加middle接着比,直到没有,如果还相同比名字. 析:很水的题,就不用说了. 代码如下: #pragma comment(link ...

  10. iOS 中的UIWindow

    使用Xcode新建一个工程后,Xcode会自动新建一些文件,其中有AppDelegate.h,AppDelegate.m,ViewController.h,ViewController.m,Main. ...