Web Navigation - POJ 1028 栈
来源:互联网 发布:ios 蜂窝数据开关 快捷 编辑:程序博客网 时间:2024/05/17 06:50
Web Navigation
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 28645 Accepted: 12819
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
题意:模拟网页的后退和前进。
思路:用栈进行记录。
AC代码如下:
#include<cstdio>#include<cstring>#include<stack>#include<string>#include<iostream>using namespace std;stack<string> st1;stack<string> st2;int main(){ int i,j,k; string s1="http://www.acm.org/",s; while(true) { cin>>s; if(s[0]=='V') { while(!st2.empty()) st2.pop(); st1.push(s1); cin>>s1; cout<<s1<<endl; } else if(s[0]=='B') { if(st1.empty()) printf("Ignored\n"); else { st2.push(s1); s1=st1.top(); st1.pop(); cout<<s1<<endl; } } else if(s[0]=='F') { if(st2.empty()) printf("Ignored\n"); else { st1.push(s1); s1=st2.top(); st2.pop(); cout<<s1<<endl; } } else if(s[0]=='Q') break; }}
0 0
- Web Navigation - POJ 1028 栈
- 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
- 不同浏览器加载JS不同解决方案——defer
- cocos2dx init 和onEnter
- tslib移植
- GUTI,Globally Unique Temporary UE Identity,全球唯一临时UE标识。
- Linux源码安装过程中选项—prefix的作用
- Web Navigation - POJ 1028 栈
- Handler介绍
- Ubuntu 入门 及 常见问题 及 解决方法
- Scala类和对象的学习
- cocos2dx异步创建对话框的问题
- 一线城市
- 2014 北京邀请赛ABDHJ题解
- DIV+CSS中更为见解的清理浮动的方式
- 下一代网络技术,你做好准备了吗