toj-1196-网站的浏览记录
来源:互联网 发布:淘宝详情页ps怎么做 编辑:程序博客网 时间:2024/06/05 14:45
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 <url>: 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/BACKBACKBACKFORWARDVISIT http://www.ibm.com/BACKBACKFORWARDFORWARDFORWARDQUIT
Sample Output
http://acm.ashland.edu/http://acm.baylor.edu/acmicpc/http://acm.ashland.edu/http://www.acm.org/Ignoredhttp://acm.ashland.edu/http://www.ibm.com/http://acm.ashland.edu/http://www.acm.org/http://acm.ashland.edu/http://www.ibm.com/Ignored
方法一:利用两个栈前后相夹记录进退
#include <stack>
using namespace std;
{
string order, nowweb;
stack<string>web;
stack<string>Oweb;
nowweb = "http://www.acm.org/";
cin >> order;
{
if(order=="VISIT")
{
while(!Oweb.empty())
Oweb.pop();
web.push(nowweb);//与下面的nowweb不一样
cin >> nowweb;
cout << nowweb << endl;
}
else if(order == "BACK")
{
if(web.empty())
cout << "Ignored" << endl;
else
{
Oweb.push(nowweb);
nowweb = web.top();
web.pop();
cout << nowweb << endl;
}
}
else if(order == "FORWARD")
{
if(Oweb.empty())
cout << "Ignored" << endl;
else
{
web.push(nowweb);
nowweb = Oweb.top();
Oweb.pop();
cout << nowweb << endl;
}
}
cin >> order;
}
return 0;
}
- toj-1196-网站的浏览记录
- 网站记录文章浏览数的做法
- 制作网站产品浏览记录
- Cookie记录浏览过的商品,商城类网站
- cookie的浏览记录
- 浏览的网站:
- 经常浏览的网站
- js记录用户在网站的浏览记录和停留时间
- js记录用户在网站的浏览记录和停留时间(2)
- 记录浏览过的商品
- 记录浏览过的商品
- 清除浏览记录的Cookie
- 浏览过的博客记录
- 我经常浏览的网站
- 浏览的网站参考价值
- 大学生值得浏览的网站
- 值得浏览的技术网站
- 常浏览的技术网站
- luogu P1060 开心的金明
- M函数的使用
- 三层架构Bll中报错找不到可接受类型为“Lesson.DAL.StudentDal”的第一个参数的扩展方法
- C++函数重载与重载原理:命名倾轧
- 浅析爬虫nutch2.0(一)
- toj-1196-网站的浏览记录
- Python RE 模块简介
- AtCoder Regular Contest 073 D
- SQLServer的最大连接数
- PHP设计模式系列(九):观察者模式
- JavaScript基础(1)之数据类型
- spring源码(9)自定义标签与自定义标签的解析
- 把字符串转换成整数
- 家用路由器 实现 Web认证