POJ 1028 Web Navigation 题解
考查代码能力的题目。也能够说是算法水题,呵呵。
推荐新手练习代码能力。
要添加难度就使用纯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 题解的更多相关文章
- poj 1028 Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31088 Accepted: 13933 ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
- poj 1028 Web Navigation 【模拟题】
题目地址:http://poj.org/problem?id=1028 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://ac ...
- 1028 Web Navigation
题目链接: http://poj.org/problem?id=1028 题意: 模拟浏览器的前进/后退/访问/退出 的四个操作. 输出当前访问的URL或者Ignore(如果不能前进/后退). 分析: ...
- poj 1208 Web Navigation(堆栈操作)
一.Description Standard web browsers contain features to move backward and forward among the pages re ...
- POJ 1028:Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30828 Accepted: 13821 ...
- POJ1028 Web Navigation
题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...
- POJ 2823 Sliding Window 题解
POJ 2823 Sliding Window 题解 Description An array of size n ≤ 106 is given to you. There is a sliding ...
- poj 2352 & Ural 1028 数星星 题解
一道水题,由于x坐标递增y坐标也递增于是前缀和统计即可,用树状数组实现. #include<bits/stdc++.h> using namespace std; const int ma ...
随机推荐
- 如何track存储过程的编译次数
原文:如何track存储过程的编译次数 转载自此处 有个script我们很熟悉,是用来去查找当前SQL Server中哪些存储过程变重编译的次数最多的: --Gives you the top 25 ...
- 3D-HEVC的TAppDecorder
一.点击项目右键设为启动项目. 二.配置文件 右键点击属性->点配置属性的Debugging,在command arguments一栏填上编码时生成的.bit文件和希望解码后文件的命名,在wor ...
- HTML5中类jQuery选择器querySelector的高级使用 document.querySelectorAll.bind(document);
基本用法 querySelector 该方法返回满足条件的单个元素.按照深度优先和先序遍历的原则使用参数提供的CSS选择器在DOM进行查找,返回第一个满足条件的元素. ----> querySe ...
- 前端angularjs+requirejs+dhtmlx 后端asp.net webapi
享一个前后端分离方案源码-前端angularjs+requirejs+dhtmlx 后端asp.net webapi 一.前言 半年前左右折腾了一个前后端分离的架子,这几天才想起来翻出来分享给大家 ...
- registerForRemoteNotificationTypes: is not supported in iOS 8.0 and
注册模式: if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedA ...
- (大数据工程师学习路径)第四步 SQL基础课程----SQL介绍及mysql的安装
一.数据库和SQL介绍 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它的产生距今已有六十多年.随着信息技术和市场的发展,数据库变得无处不在:它在电子商务.银行系统等众多领域都 ...
- LeetCode——Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...
- Merge into的使用详解-你Merge了没有
Merge是一个非常有用的功能,类似于Mysql里的insert into on duplicate key. Oracle在9i引入了merge命令, 通过这个merge你能够在一个SQL语句中对一 ...
- MVC自定义配置
ASP.NET 5 入门 (2) – 自定义配置 ASP.NET 5 理解和入门 建立和开发ASP.NET 5 项目 初步理解ASP.NET5的配置 正如我的第一篇文章ASP.NET 5 (vNext ...
- uva757 - Gone Fishing(馋)
题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...