Web Navigation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 31906   Accepted: 14242

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.

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

思路:
终于通过这道题目尝试了下C++里面的string类,结果发现尼玛和java里面的完全没两样啊
没有太大的难度,就是按照题目的操作模拟一下就可以,有个地方第一次提交的时候出错了,就是BACK和FORWARD这两种情况
当stack为空的时候,他们是不会把tmp_url压进栈的,这点一开始没有注意到,debug一下就发现了
还有一开始准备用switch,结果发现这个函数只能够对int型变量操作

#include <iostream>
#include <stack>
#include <string>
using namespace std; int main()
{
string command;
stack<string> f,b;
string tmp_url = "http://www.acm.org/";
string new_url; while(cin>>command) {
if(command == "VISIT") {
b.push(tmp_url);
cin>>tmp_url;
while(!f.empty()){f.pop();}
cout<<tmp_url<<endl;
}
if(command == "BACK") {
if(!b.empty()) {
f.push(tmp_url);
tmp_url = b.top();
b.pop();
cout<<tmp_url<<endl;
}
else {
cout<<"Ignored"<<endl;
}
}
if(command == "FORWARD") {
if(!f.empty()) {
b.push(tmp_url);
tmp_url = f.top();
f.pop();
cout<<tmp_url<<endl;
}
else {
cout<<"Ignored"<<endl;
}
}
if(command == "QUIT")
break;
}
return ;
}

POJ-1028(字符串模拟)的更多相关文章

  1. 用字符串模拟两个大数相加——java实现

    问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...

  2. HDU-3787(字符串模拟)

    Problem Description 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开.现在请计算A+B的结果,并以正常形式输出.   Input 输入包含 ...

  3. HDU-1002.大数相加(字符串模拟)

    本题大意:给出两个1000位以内的大数a 和b,让你计算a + b的值. 本题思路:字符串模拟就能过,会Java的大佬应该不会点进来...... 参考代码: #include <cstdio&g ...

  4. Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)

    题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...

  5. HDU-Digital Roots(思维+大数字符串模拟)

    The digital root of a positive integer is found by summing the digits of the integer. If the resulti ...

  6. Vigenère密码 2012年NOIP全国联赛提高组(字符串模拟)

    P1079 Vigenère 密码 题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简 ...

  7. CCF(JSON查询:40分):字符串+模拟

    JSON查询 201709-3 纯字符串模拟,考的就是耐心和细心.可惜这两样我都缺... #include<iostream> #include<cstdio> #includ ...

  8. poj 1028 Web Navigation(模拟)

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

  9. poj 1028 Web Navigation 【模拟题】

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

  10. 【stack】模拟网页浏览 poj 1028

    #include<stdio.h> #include<string.h> int main() { ][]; ]; int i,depth; strcpy(s[]," ...

随机推荐

  1. struts开发&lt;struts中的action详细配置. 二&gt;

    在eclipse中新建项目StrutsDemo1[struts的配置见]struts开发<在eclipse中配置struts. 一> 详细文件夹结构例如以下 第一种配置方法 新建UserA ...

  2. Eclipse(MyEclipse)使用技巧——改动凝视字体大小

    Eclipse在安装完毕后,凝视的字体大小远远小于代码的大小,依照网上查的相关信息 窗体--首选项--常规--外观--颜色和字体--基本--文本字体--编辑 Window -->Preferen ...

  3. 【剑指offer】和为定值的连续正数序列

    .可是他并不满足于此,他在想到底有多少种连续的正数序列的和为100(至少包含两个数).没多久,他就得到还有一组连续正数和为100的序列:18,19,20,21,22.如今把问题交给你,你能不能也非常快 ...

  4. (转) [教程] Unity3D中角色的动画脚本的编写(一)

    ps: 这两天研究unity3d,对动画处理特别迷糊,不知FBX导入以后,接下来应该怎么操作,看到这篇文章,感觉非常好,讲解的很详细. 已有好些天没写什么了,今天想起来该写点东西了.这次我所介绍的内容 ...

  5. Android android-common 常用功能和工具集合

    本文内容 环境 android-common 项目结构 演示 android-common 参考资料 android-common 主要包括如下内容: 缓存,包括图片缓存.预取缓存.网络缓存. 公共 ...

  6. 【转】非常详细的docker学习笔记

    一.Docker 简介 Docker 两个主要部件: Docker: 开源的容器虚拟化平台 Docker Hub: 用于分享.管理 Docker 容器的 Docker SaaS 平台 -- Docke ...

  7. sass笔记-2|Sass基础语法之让样式表更具条理性和可读性

    这一篇主要详述保持sass条理性和可读性的3个最基本方法--嵌套.导入和注释. 零. 变量 变量本身的作用是为了保持属性值的可维护性,把所有需要维护的属性值放在同一个地方,快速更改,处处生效,可谓售后 ...

  8. Linux 最大进程数

    前言 使用环境:centos 7系统 一.查看用户打开的最大进程数 ulimit -a max user processes              (-u) #系统限制某用户下最多可以运行多少进程 ...

  9. css3 3D变换和动画

    3D变换和动画 建立3D空间,transform-style: preserve-3d perspective: 100px; 景深 perspective-origin:center center ...

  10. ORACLE输出详细错误信息错误行数

    ... COMMIT; --输出成功信息 DBMS_OUTPUT.PUT_LINE('RUN RESULT: SUCCESS'); EXCEPTION WHEN OTHERS THEN BEGIN R ...