考查代码能力的题目。也能够说是算法水题,呵呵。

推荐新手练习代码能力。

要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈。做多了,我就直接使用STL了。

#include <stdio.h>
#include <iostream>
#include <stack>
#include <string>
using namespace std; int main()
{
stack<string> forward;
stack<string> backward;
string cur = "http://www.acm.org/";
string cmd; while (cin>>cmd)
{
if (cmd == "QUIT") break; if (cmd == "VISIT")
{
backward.push(cur);
cin>>cur;
puts(cur.c_str());
forward = stack<string>();
}
else if (cmd == "BACK")
{
if (backward.empty())
{
puts("Ignored");
}
else
{
forward.push(cur);
cur = backward.top();
backward.pop();
puts(cur.c_str());
}
}
else if (cmd == "FORWARD")
{
if (forward.empty())
{
puts("Ignored");
}
else
{
backward.push(cur);
cur = forward.top();
forward.pop();
puts(cur.c_str());
}
}
}
return 0;
}

POJ 1028 Web Navigation 题解的更多相关文章

  1. poj 1028 Web Navigation

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

  2. poj 1028 Web Navigation(模拟)

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

  3. poj 1028 Web Navigation 【模拟题】

    题目地址:http://poj.org/problem?id=1028 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://ac ...

  4. 1028 Web Navigation

    题目链接: http://poj.org/problem?id=1028 题意: 模拟浏览器的前进/后退/访问/退出 的四个操作. 输出当前访问的URL或者Ignore(如果不能前进/后退). 分析: ...

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

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

  6. POJ 1028:Web Navigation

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

  7. POJ1028 Web Navigation

    题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...

  8. POJ 2823 Sliding Window 题解

    POJ 2823 Sliding  Window 题解 Description An array of size n ≤ 106 is given to you. There is a sliding ...

  9. poj 2352 & Ural 1028 数星星 题解

    一道水题,由于x坐标递增y坐标也递增于是前缀和统计即可,用树状数组实现. #include<bits/stdc++.h> using namespace std; const int ma ...

随机推荐

  1. Java - 面向对象(object oriented)计划 详细解释

    面向对象(object oriented)计划 详细解释 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24058107 程序包括 ...

  2. POJ 3414--Pots(BFS+回溯路径)

    Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9963   Accepted: 4179   Special Ju ...

  3. BizTalk开发小技巧

    BizTalk开发小技巧 随笔分类 - Biztalk Biztalk 使用BizTalk实现RosettaNet B2B So Easy 摘要: 使用BizTalk实现RosettaNet B2B ...

  4. 【Java】【Flume】Flume-NG源代码分析的启动过程(两)

    本节分析配置文件的解析,即PollingPropertiesFileConfigurationProvider.FileWatcherRunnable.run中的eventBus.post(getCo ...

  5. 【Linux命令】--(9)其他常用命令

    其他常用命令+++++++++++++++++++++++++++++++lndiffdatecal grep wcpswatchatcrontab++++++++++++++++++++++++++ ...

  6. Node.js可以做些什么?

    就像 JavaScript 至client天生,Node.js 生于网络.Node.js 我们可以做更多的不是开发一个网络 站这么简单,采用 Node.js.您可以轻松地开发:  具有复杂逻辑的站点 ...

  7. Extjs 4.2 右键菜单树节点(,选择逆,废除)

    写自己的最新版本号extjs4.2树节点的操作,记录它,可能在将来被用于. var tree = new Ext.tree.TreePanel({ flex: 1, animate: true, au ...

  8. Ansible@一个有效的配置管理工具--Ansible configure management--翻译(十)

    未经书面许可,.请勿转载 Custom Modules Until now we have been working solely with the tools provided to us by A ...

  9. android 拍照注意问题

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, reqCode) ...

  10. [Unity3D]Unity3D游戏开发之Logo渐入渐出效果的实现

    ---------------------------------------------------------------------------------------------------- ...