Web Navigation

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 33281   Accepted: 14836

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

Source

 
分析: 水题,题目怎么说就怎么做。
 
 #include <stdio.h>
#include <string.h> #define MAX_NUM 100 int main()
{
char input[MAX_NUM];
char now[MAX_NUM] = "http://www.acm.org/";
char stackForward[MAX_NUM][MAX_NUM];
char stackBack[MAX_NUM][MAX_NUM];
int stackF = ;
int stackB = ; memset(stackForward, , MAX_NUM * MAX_NUM * sizeof(char));
memset(stackBack, , MAX_NUM * MAX_NUM * sizeof(char)); while()
{
scanf(" %s",input);
if(strcmp(input, "VISIT") == )
{
stackF = ;
strcpy(stackBack[stackB++], now);
scanf(" %s", now);
}
else if(strcmp(input, "BACK") == )
{
if(stackB == )
{
printf("Ignored\n");
continue;
}
strcpy(stackForward[stackF++], now);
strcpy(now, stackBack[--stackB]);
}
else if(strcmp(input, "FORWARD") == )
{
if(stackF == )
{
printf("Ignored\n");
continue;
}
strcpy(stackBack[stackB++], now);
strcpy(now, stackForward[--stackF]);
}
else if(strcmp(input, "QUIT") == )
{
break;
}
printf("%s\n", now);
} return ;
}

北大poj- 1028的更多相关文章

  1. 北大POJ题库使用指南

    原文地址:北大POJ题库使用指南 北大ACM题分类主流算法: 1.搜索 //回溯 2.DP(动态规划)//记忆化搜索 3.贪心 4.图论 //最短路径.最小生成树.网络流 5.数论 //组合数学(排列 ...

  2. poj 1028

    http://poj.org/problem?id=1028 题意(水):做一个游览器的历史记录. back:后退到上一个页面,当上一个页面没有时,输出ignored. forward:向前一个页面, ...

  3. poj 1028 Web Navigation(模拟)

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

  4. poj 1028 Web Navigation

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

  5. poj 1028 Web Navigation 【模拟题】

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

  6. POJ 1028解答

    #include <iostream>#include <cstdio>#include <cmath>#include <stack>#include ...

  7. POJ 1028题目描述

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

  8. POJ 1028 Web Navigation 题解

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

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

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

  10. POJ 1028:Web Navigation

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

随机推荐

  1. 在Spring里进行单元测试Junit

    搭建Spring环境(自行搭建): @RunWith注解指定使用springJunit的测试运行器 @ContextConfiguration注解指定测试用的spring配置文件的位置 import ...

  2. centos6.5下安装qq2012

    大家如果想在linux下用QQ的话,最好的方法就是用wine来安装.腾讯的QQ for linux用起来很坑爹. 下面就是我用wine在centOS下安装QQ.中间过程很简单. 一.安装Wine. 1 ...

  3. 最佳的 14 个免费的响应式 Web 设计测试工具

    一旦你决定要搭建一个网站就应该已经制定了设计标准.你认为下一步该做什么呢?测试!我使用“测试”这个词来检测你网站对不同屏幕和浏览器尺寸的响应情况.测试在响应式网页设计的过程中是很重要的一步.如果你明白 ...

  4. stopping NetworkManager daemon failed

    1 初次安装NetworkManager时发现,无法将这个服务关闭 2 上网找了一圈,也没找到原因 3 重启服务器后就能正常关闭了 4 将该服务删除重装也能正常关闭 5 下回重装系统时再观察一下

  5. 声明变量,一定要用 var!

    public static T TryGet<T>(Func<T> func, T ifError = default(T)) { try { return func(); } ...

  6. 即时聊天IM之二 openfire 整合现有系统用户

    合肥程序员群:49313181.    合肥实名程序员群:128131462 (不愿透露姓名和信息者勿加入) Q  Q:408365330     E-Mail:egojit@qq.com  综述: ...

  7. Hibernate与MyBatis

    一. Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Mybatis 是另外一种优秀的O/R ...

  8. Web自动化基础(一)使用Selenium定位元素

    什么是元素?我们知道网页上有什么内容显示出来,比如一个按钮,一个输入框,一张图片,都可以理解成元素,这些元素是由html代码构成的,比如图片可以用<img>标签来展示,一个输入框可以用&l ...

  9. guava学习--monitor

    转载:https://my.oschina.net/realfighter/blog/349924   https://my.oschina.net/realfighter/blog/349926 M ...

  10. 对COM 组件的调用返回了错误 HRESULT E_FAIL

    .net ppt转pdf时报以下错误: 对COM 组件的调用返回了错误 HRESULT E_FAIL 在服务器端打开PPT,选项--另存为--PDF,发现PowerPoint报了个错误: “无法找到打 ...