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. android JNI开发

    1.NDK简介 NDK(Native Development Kit)NDK提供了一系列的工具,帮助开发者快速开发C(或C++)的动态库,并能自动将so和java应用一起打包成apk.NDK集成了交叉 ...

  2. web.xml中的contextConfigLocation在spring中的作用

    在web.xml中通过contextConfigLocation配置spring, contextConfigLocation参数定义了要装入的 Spring 配置文件.默认会去/WEB-INF/下加 ...

  3. 查找数组中重复项的index

    var ary = [5, 4, 4, 2, 7, 8, 33, 2222, 99, 88]; function isRepeat(arr) { var hash = {}; for (var i=0 ...

  4. Discuz论坛安全加固浅析

    [51CTO专稿]Discuz! 论坛以其功能完善.效率高效.负载能力,深受被大多数的网站喜爱和青睐.无独有隅,笔者所维护的论坛就是用discuz! 来构建的,从接手时候的7.2到现在x2.0,经历了 ...

  5. 20169212《Linux内核原理与分析》第八周作业

    理论 task_struct的结构关系 非常庞大的数据结构,400多行代码.包括对进程链表的管理,控制台,文件系统描述,文件描述符,内存管理描述,信号描述等. 创建一个新进程在内核中的执行过程 for ...

  6. C#如何通过Socket的方式获取httponly cookie

    正常情况下C#可以使用HttpWebRequest.HttpWebResponse和CookieContainer类来获取Cookie,但是当Cookie设置为httponly,我们就不能用上面的方法 ...

  7. mysql取前几行数据limit用法

    转自http://www.cnblogs.com/study100/archive/2013/07/30/3224250.html 在mysql中是没有top关键字的,在mysql中可以用limit来 ...

  8. MYSQL5.7版本sql_mode=only_full_group_by问题

    具体出错提示: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggr ...

  9. PHP数学函数

    Abs: 取得绝对值. Acos: 取得反余弦值. Asin: 取得反正弦值. Atan: 取得反正切值. Atan2: 计算二数的反正切值. base_convert: 转换数字的进位方式. Bin ...

  10. JSP页面中的精确到秒的时间控件

    技术:Struts1+jsp+MSql 需求:ncmgt网络监控系统中显示用户的操作日志,并且根据操作时间查询用户的详细操作记录.时间精确到秒 大致效果如下.上图! 大家可以清晰的看到.红色画线部分就 ...