POJ 1028 / East Central North America 2001 Web Navigation (栈)
来源:互联网 发布:数据库开发和dba 编辑:程序博客网 时间:2024/05/18 02:55
Web Navigation
http://poj.org/problem?id=1028
Time Limit: 1000MS
Memory Limit: 10000K
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/
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/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
/*0ms,164KB*/#include<iostream>#include<string>using namespace std;string stack[101];int main(void){ int top = 0, Max = 0;string op;stack[top] = "http://www.acm.org/";while (cin >> op, op[0] != 'Q'){if (op[0] == 'V'){string web;cin >> web;stack[++top] = web;cout << web << endl;Max = top;}else if (op[0] == 'B'){if (top != 0)cout << stack[--top] << endl;else cout << "Ignored" << endl;}else//'F'{if (top < Max)cout << stack[++top] << endl;else cout << "Ignored" << endl;}}return 0;}
- POJ 1028 / East Central North America 2001 Web Navigation (栈)
- East Central North America 2006
- 【poj 1502】 MPI Maelstrom 【East Central North America 1996】
- East Central North America 1999 "Gone Fishing"
- East Central North America 2004 I Conduit!
- North America - East Central NA 2013
- North America - East Central NA 2012
- POJ 1016 测试数据( East Central North America 1998 Numbers That Count Test data )
- UVa 755 / POJ 1002 / East Central North America 1999 487--3279 (排序)
- ACM ICPC East Central North America 1994_Simply Syntax
- 130825组队赛-Regionals 2012, North America - East Central NA
- 20131004组队赛-Regionals 2010, North America - East Central NA
- 组队赛131004 Regionals 2010, North America - East Central NA
- hdu 1063 Exponentiatio(East Central North America 1988)
- UVa 757 / POJ 1042 / East Central North America 1999 Gone Fishing (枚举&贪心&想法题&优先队列)
- 2010 East Central North America Region F 题 Pro-Test Voting 解题报告
- 组队练习赛(Regionals 2012, North America - East Central NA)
- HNU 13064 Cuckoo for Hashing解题报告 North America - East Central 2013
- jQuery Ajax 全解析
- c# 调用 .cs 生成的 dll 文件
- 自学js 分享
- 链表交叉(2012.5.6百度实习)
- andorid 四种自带的dialog
- POJ 1028 / East Central North America 2001 Web Navigation (栈)
- 前后中括号正则匹配
- word文档转换为txt-python
- 安慰你的用户
- AutoCAD:ObjectARX所有版本下载地址
- Android自定义对话框(Dialog)位置,大小
- hdu 2082 找单词 母函数
- Java IO流相关知识
- JS控制滚动条的位置