TOJ 1196. Web Navigation
来源:互联网 发布:淘宝店铺号有什么用 编辑:程序博客网 时间:2024/06/07 10:00
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<iostream>#include<string>#include<stack>using namespace std;int main(){string s,y="http://www.acm.org/";stack<string>m,n;while(cin>>s&&s!="QUIT"){if(s=="VISIT"){cin>>s;cout<<s<<endl;if(m.empty())m.push(y);m.push(s);while(!n.empty())n.pop();}else if(s=="BACK"){if(!m.empty()){if(m.top()!=y)n.push(m.top());m.pop();if(m.empty())cout<<"Ignored"<<endl;elsecout<<m.top()<<endl;}elsecout<<"Ignored"<<endl;}else if(s=="FORWARD"){if(n.empty())cout<<"Ignored"<<endl;else{if(m.empty())m.push(y);m.push(n.top());n.pop();cout<<m.top()<<endl;}}}return 0;}
- TOJ 1196. Web Navigation
- Web Navigation
- Web Navigation
- Web Navigation
- Web Navigation
- Web Navigation
- Web Navigation
- Web Navigation
- Web Navigation
- zoj1061 Web Navigation
- PKU 1028 Web Navigation
- ZOJ-1061-Web Navigation
- fjnu 1060 Web Navigation
- 1028 Web Navigation
- poj1028 Web Navigation
- ZOJ1061 Web Navigation
- POJ 1028 Web Navigation
- POJ Web Navigation
- 用array辅助初始化set
- CentOS 64位下安装Postfix+Dovecot 配置邮件服务器笔记
- Ul li排版使用
- 在XAML代码中导入名称空间
- 存个sublime text 配置c++代码
- TOJ 1196. Web Navigation
- Intel Galileo笔记(二)linux 编译
- LeetCode——Merge Sorted Array
- linux下signal函数
- c++中动态内存操作
- C++ vector介绍
- FMDataBaseQueue 返回值
- poj 1459 Power Network (dinic)
- 评一名青鸟学生的学习