题目来源:http://poj.org/problem?id=1028

题目大意:

  模拟实现一个浏览器的“前进”和“回退”功能。由一个forward stack和一个backward stack实现。

  打开浏览器时的正位于http://www.acm.org/。然后浏览器会接受下面四种命令:

  BACK:将当前页面压入forward stack,将backward stack顶部页面弹出,成为当前页面。若当前backward stack为空,忽略该命令;

  FORWARD:将当前页面压入backward stack,将forward stack顶部的页面弹出,作为当前页面。若当前forward stack为空,忽略该命令;

  VISIT:将当前页面压入backward stack,将指定的URL作为当前页面;

  QUIT:退出浏览器。

输入:命令的序列,以QUIT作为结束。

输出:如果当前页面发生了改变,输出改变后的当前页面,如果命令被忽略,输出“Ignored.”


Sample Input

VISIT http://acm.ashland.edu/
VISIT http://acm.baylor.edu/acmicpc/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT

Sample Output

http://acm.ashland.edu/
http://acm.baylor.edu/acmicpc/
http://acm.ashland.edu/
http://www.acm.org/
Ignored
http://acm.ashland.edu/
http://www.ibm.com/
http://acm.ashland.edu/
http://www.acm.org/
http://acm.ashland.edu/
http://www.ibm.com/
Ignored

题干已经把如何实现讲解得很清楚,照着写就可以了,要是不给提示,这倒会是道很有意思的题。

 //////////////////////////////////////////////////////////////////////////
// POJ1028 Web Navigation
// Memory: 264K Time: 47MS
// Language: C++ Result: Accepted
////////////////////////////////////////////////////////////////////////// #include <iostream>
#include <string>
#include <stack> using namespace std; stack<string> forwardStack;
stack<string> backwardStack; void clearForwardStack() {
while (!forwardStack.empty()) {
forwardStack.pop();
}
} int main() {
string operation;
string currentURL = "http://www.acm.org/";
string nextURL;
while (cin >> operation && operation != "QUIT") { switch (operation[]) {
case 'V':
cin >> nextURL;
backwardStack.push(currentURL);
currentURL = nextURL;
cout << currentURL << endl;
clearForwardStack();
break;
case 'B':
if (backwardStack.empty()) {
cout << "Ignored" << endl;
} else {
forwardStack.push(currentURL);
currentURL = backwardStack.top();
cout << currentURL << endl;
backwardStack.pop();
}
break;
case 'F':
if (forwardStack.empty()) {
cout << "Ignored" << endl;
} else {
backwardStack.push(currentURL);
currentURL = forwardStack.top();
cout << currentURL << endl;
forwardStack.pop();
}
break;
}
}
system("pause");
return ;
}

POJ1028 Web Navigation的更多相关文章

  1. POJ-1028 Web Navigation 和TOJ 1196. Web Navigation

    Standard web browsers contain features to move backward and forward among the pages recently visited ...

  2. [POJ1028]Web Navigation(栈)

    这题是01年East Central North的A题,目测是签到题 Description Standard web browsers contain features to move backwa ...

  3. poj 1028 Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31088   Accepted: 13933 ...

  4. POJ 1028:Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30828   Accepted: 13821 ...

  5. Web Navigation

    Description Standard web browsers contain features to move backward and forward among the pages rece ...

  6. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  7. poj 1208 Web Navigation(堆栈操作)

    一.Description Standard web browsers contain features to move backward and forward among the pages re ...

  8. ZOJ 1061 Web Navigation

    原题链接 题目大意:模拟一个浏览器,打开一个网页.后退或者前进,输出网址. 解法:用两个堆栈分别表示后退保存的网页和前进保存的网页.初始化时把当前页面压入后退堆栈的栈顶.要注意几点,一个是每次记得要清 ...

  9. POJ 1028 Web Navigation 题解

    考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...

随机推荐

  1. RTP 打包H264与AAC

    static int h264_parse(Track *tr, uint8_t *data, size_t len) { h264_priv *priv = tr->private_data; ...

  2. ACM学习历程—HDU5592 ZYB's Premutation(逆序数 && 树状数组 && 二分)(BestCoder Round #65 1003)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5592 题目大意就是给了每个[1, i]区间逆序对的个数,要求复原原序列. 比赛的时候2B了一发. 首先 ...

  3. JS数组的sort排序

    数组sort方法排序var aa=[6,2,1,5]//默认是从小到大排序aa.sort()[1, 2, 5, 6] //下面也是从小到大排序aa.sort(function(a,b){return ...

  4. Linux mount指令

    -o,是指option,可以指定username,password:当时我们就碰到一个坎,如何来避免输入用户名密码,其实本质并不是避免输入用户名米吗,而是某种可知的方式来进行权限控制:解决的方式就是采 ...

  5. UOJ #348 州区划分 —— 状压DP+子集卷积

    题目:http://uoj.ac/problem/348 一开始可以 3^n 子集DP,枚举一种状态的最后一个集合是什么来转移: 设 \( f[s] \) 表示 \( s \) 集合内的点都划分好了, ...

  6. Poj 2533 Longest Ordered Subsequence(LIS)

    一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...

  7. HDOJ1059(多重背包)

    1.解法一:多重背包 #include<iostream> #include<cstdio> using namespace std; #define MAX(a,b) (a& ...

  8. tomcat安装与运行

    实验环境:CentOS7 使用系统yum仓库安装: #安装基本包和开发工具包 [root@~ localhost]#yum install -y java-1.8.0-openjdk java-1.8 ...

  9. qtp ie_hook

    今天要讲的内容是注册异类子控件授予强制HOOK,名字有点抽象,简单的说就是在一个QTP可识别的A类插件窗口对象中存在着B类插件的控件对象, 最常见的例子就是在应用程序中内嵌一个Browser对象子控件 ...

  10. springMVC绑定json参数之二(2.1.1)

    二.springmvc 接收不同格式的json字符串 1.首先扫盲几个知识点: 例子如下: 前台传递json对象(这里uu[0]的名字uu要和Test对象中的属性List<User>名称对 ...