POJ 1028----Web Navigation
来源:互联网 发布:sql select两个表 编辑:程序博客网 时间:2024/05/16 11:49
Web Navigation
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 29478 Accepted: 13169
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
问题描述:
根据要求写出网址。。;
用今天刚学的队列写的。
#include<cstdio>#include<iostream>#include<stack>using namespace std;int main(){ stack<string> s1,s2; string s,str; s1.push("http://www.acm.org/"); while(cin >> s) { if(s=="QUIT") break; if(s=="VISIT") { cin >> str; cout << str << endl; s1.push(str); while(!s2.empty()) { s2.pop(); } } if(s=="BACK") { if(s1.size()>=2) { s2.push(s1.top()); s1.pop(); cout << s1.top() << endl; } else cout << "Ignored" << endl; } if(s=="FORWARD") { if(!s2.empty()) { s1.push(s2.top()); s2.pop(); cout << s1.top() << endl; } else cout << "Ignored" << endl; } } return 0;}
0 0
- POJ 1028 Web Navigation
- POJ 1028 Web Navigation
- poj 1028 Web Navigation
- Web Navigation poj 1028
- poj 1028 Web Navigation
- POJ-1028-Web Navigation
- poj 1028 Web Navigation
- poj-1028 Web Navigation
- POJ 1028 Web Navigation
- poj 1028 Web Navigation
- POJ 1028 Web Navigation
- POJ 1028 - Web Navigation
- POJ 1028 Web Navigation
- poj 1028 Web Navigation
- POJ 1028 Web Navigation
- POJ 1028 - Web Navigation
- POJ 1028----Web Navigation
- poj 1028-Web Navigation
- Qt 中使用 C++11
- (图解)Description Resource Path Location Type Java compiler level does not match the version of
- uva 11825 黑客的攻击 状态dp 典型
- javascript 加入收藏
- itoa 函数!!!(window平台下)
- POJ 1028----Web Navigation
- UI线程阻塞问题
- C之诡谲
- hdu2196 Computer 树形DP 树上点到其它点的最远距离
- python K-Means 实例二则
- ViewPager + Fragment 实现页面滑动
- nginx和tomcat之间连接复用要注意的问题
- .NET基础回顾
- C语言学习资源汇总