Web Navigation_poj1028_模拟
来源:互联网 发布:windows exp导出数据库 编辑:程序博客网 时间:2024/06/08 11:36
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/
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.
Analysis
再一次体会到IO流的强大之处
听说复赛提高考模拟频率很高啊(只是在找理由刷水题)
直接两个栈无脑模拟就可以了
Code
#include <iostream>#include <string.h>#include <stack>using namespace std;stack<string>f;stack<string>b;string s,c;int main(){ string now="http://www.acm.org/"; while (cin>>s&&s!="QUIT") { if (s=="VISIT") { cin>>c; while (!f.empty()) f.pop(); b.push(now); now=c; cout<<now<<endl; } if (s=="BACK") { if (b.size()) { f.push(now); now=b.top(); b.pop(); cout<<now<<endl; } else { cout<<"Ignored"<<endl; } } if (s=="FORWARD") { if (f.size()) { b.push(now); now=f.top(); f.pop(); cout<<now<<endl; } else { cout<<"Ignored"<<endl; } } } return 0;}
- Web Navigation_poj1028_模拟
- WEB 技术模拟应用程序
- WEB 技术模拟应用程序
- 模拟真实Web站点
- 【模拟】Web浏览
- 模拟Web服务器
- java 模拟web登录
- C#模拟web服务器
- Servlet模拟Web服务器
- Java模拟web服务器
- android模拟web服务器
- C#模拟web服务器
- Web浏览(简单模拟)
- 模拟Web服务器
- C#模拟web服务器
- web服务器模拟实现
- golang模拟web上传
- web-模拟鼠标事件
- 云梦微信系统的一个坑
- JavaScript中的常见转义字符
- Java 线程池原理和队列详解
- iOS 获取摄像头视频
- Android MVP 项目分析
- Web Navigation_poj1028_模拟
- 个性化 圆形图片
- 新闻分析:美国网络遭攻击暴露物联网安全隐患
- pdf转换成excel格式的方法简介
- java 字符串匹配src 获取值
- Android输出Log控制
- web08
- web app页面开发必备
- leetcode 55. Jump Game