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

推荐新手练习代码能力。

要添加难度就使用纯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. 如何成为游戏的生产者——第二章:如何开始你的编程(开发环境的搭建、C++语言适应)

    如何成为游戏的生产者--文章二章:怎样開始你的编程 小故事:上节说到我六年级打开了那本C语言的书,然后其实我还是没看懂.好像看懂了一些printf语句.之后遇到了史无前例的困难--怎么让代码执行起来. ...

  2. JS它DOM

    DOM:document object model.文档对象模型.它主要由许多节点.而基于JS对象的一切视角,DOM核心是节点对象和操作方法的属性.从下面三方面来介绍DOM. 一.节点查找与操作 这部 ...

  3. Windows Phone 8 ControlTiltEffect

    /* Copyright (c) 2010 Microsoft Corporation. All rights reserved. Use of this sample source code is ...

  4. struts.xml在Action配置具体解释

    在博客上我已经基本上解释struts.xml基本配置.配置过程最为基本的是action的动态配置. 一.Action的创建方法 1)实现Action接口 2)继承ActionSupport类,覆写当中 ...

  5. cocos2dx 制作单机麻将(二)

    cocos2dx 制作单机麻将(二) 打乱麻将顺序2 前面解说了怎样打乱初始给定的麻将牌堆, 另一种是打乱随意给定的麻将牌堆 //混乱扑克2 void RandAppointCardData(BYTE ...

  6. 使用javascript实现html文字不可选

    如何使用js让html该文本是不可选定它?首先想到的是用css选择实现,如下面: -webkit-touch-callout: none; -webkit-user-select: none; -kh ...

  7. M、V、C

    概述 Model-View-Controller(MVC),即模型-视图-控制器. MVC将软件系统分成三大部分:Model,View,Controller,三个部分通过某种机制通信 M.V.C的职能 ...

  8. 具体分析Struts工作流程

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXV3ZW56aGU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

  9. SQL 注意事项

    -------选择表名 配置Ctrl+3 能够select * 桌 USE [NB] GO /* 物: StoredProcedure [dbo].[SP_Select] 脚本日期: 05/28/20 ...

  10. Javascript标准类型的方法集

    1 array.concat(item...) concat方法会产生一个新数组,将一个或多个item附加在数组之后 var a = ['a', 'b', 'c'] var b = ['x', 'y' ...