PUK    1028   模拟题

http://poj.org/problem?id=1028

Web Navigatiopn

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 32531   Accepted: 14510

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

East Central North America 2001
/*
    题目大意:
            就是说我们平时访问网页一样的,若指令为 BACK :  后退    FORWARD : 前进  VISIT :访问  QUIT : 退出
*/
/*
1.initially URL http://www.acm.org/
2.用二维数组存放网址
*/
#include<iostream>
#include<cstring>

using namespace std;

int check_com(char *com)//比较函数,用来检查指令, atrcmp 函数用来比较,若相等就返回0;
{
    if (strcmp(com, "BACK") == 0)
        return 0;
    if (strcmp(com, "FORWARD") == 0)
        return 1;
    if (strcmp(com, "VISIT") == 0)
        return 2;
    if (strcmp(com, "QUIT") == 0)
        return 3;
}
int main(void)
{
    int cur = 0;
    int end = 0;
    char com[10];
    char url[110][77] = { "http://www.acm.org/"};
    while (cin >> com)
    {
        int n = check_com(com);
        switch (n)
        {
        case 0://返回上一个网址,如果前面没有了,记得回到初始的情况,这也是下面 if 条件句中的 cur++ 的原因;
        {
            cur--;
            if (cur < 0)
            {
                cout << "Ignored" << endl;
                cur++;
            }
            else
                cout << url[cur] << endl;
        }
        break;
        case 1://访问后一个网址,如果后面没有了,记得回到前面的位置,这也是下面 if 条件句中的 cur-- 的原因;
        {
            cur++;
            if (cur > end)
            {
                cout << "Ignored" << endl;
                cur--;
            }
            else
            {
                cout << url[cur] << endl;
            }
        }
        break;
        case 2://访问新的网址,并存入;
        {
            cur++;
            end = cur;
            cin >> url[cur];
            cout << url[cur] << endl;
        }
        break;
        case 3://离开也是要写上return 0 的;
            return 0;
        }
    }
    return 0;
}
/*
    后记:这种题目就是传说中的模拟题吧!感觉就是十分繁琐,弄的不好就会出错,第二次提交就错了!
*/

PUK 1028 WebNavigation相关推荐

  1. poj题目详细分类及算法推荐题目

    DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题  ...

  2. POJ ZOJ题目分类

    POJ,ZOJ题目分类(多篇整合版,分类很细致,全面) 标签: 题目分类POJ整理 2015-04-18 14:44 1672人阅读 评论(0) 收藏 举报 本文章已收录于: 分类: ACM资料(5) ...

  3. POJ,ZOJ题目分类(多篇整合版,分类很细致,全面)

    水题: 3299,2159,2739,1083,2262,1503,3006,2255,3094 初级: 一.基本算法:        (1)枚举 (1753,2965)       (2)贪心(13 ...

  4. [恢]hdu 1028

    2011-12-16 08:28:00 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意:一个整数n,可以表示为多少种和的形式. mark:dp ...

  5. PAT甲级1028 List Sorting:[C++题解]排序,cin和cout会超时

    文章目录 题目分析 题目链接 题目分析 用结构体来存,写三个排序函数. 本题需要注意的点是: 用cin来读会超时,所以用C语言的scanf来读.这样的话,就不能使用string,而是使用char数组. ...

  6. 手机PIN锁死让输入PUK解决方案

    如题:事先要知道自己手机的服务密码.登录中国移动就可以查询出来PUK,输入到手机里面就成功解锁了.然后会提示用户输入新的PIN.重新设置一个新的就OK了 转载于:https://www.cnblogs ...

  7. 1028. List Sorting (25)

    这道题目主要是排序,刚开始简单写了一个代码,发现最后一个测试数据.发现超时了,sort排序用的是快排.快排平均是O(NlogN),最坏是O(N*N).输入数据是10^5级的,最坏的情况会超过10^10 ...

  8. 百练OJ:1028:Web Navigation

    链接:http://bailian.openjudge.cn/practice/1028/ 1028:Web Navigation 描述 Standard web browsers contain f ...

  9. 1028: 在霍格沃茨找零钱

    1028: 在霍格沃茨找零钱 时间限制: 1 Sec  内存限制: 128 MB 提交: 316  解决: 147 [提交][状态][讨论版] 题目描述 如果你是哈利·波特迷,你会知道魔法世界有它自己 ...

最新文章

  1. 第二阶段第八次spring会议
  2. 10.6监控io性能10.7free命令10.8ps命令10.9查看网络状态10.10linux抓包
  3. 什么是泛型缓存和静态构造函数?
  4. 根据一级分类查询所有子级分类
  5. matplotlib的颜色和控制条
  6. 什么是张量(tensor)
  7. linux子系统 显卡,bash 漏洞?linux授权命令sudo?windows linux子系统?新手理解的bash环境变量解析漏洞...
  8. Anchor和Dock的区别
  9. 【数据结构】1、零碎知识点集合
  10. 旅游后台管理系列——使用maven构建工程
  11. ansys toolkit教程_复合材料ANSYS-ACP仿真教程.pdf
  12. 定位CPU飙升问题点
  13. 什么是SPU和SKU
  14. uoj#311. 【UNR #2】积劳成疾(期望dp)
  15. SQL:开窗函数(窗口函数)
  16. 在godaddy使用支付宝
  17. 微机接口实验一 :8255并行接口实验
  18. Windows 11 正式版 ISO 镜像下载大全
  19. 最简单的基于FFmpeg的解码器-纯净版(不包含libavformat)
  20. css定义变量(定义:--aa;使用:var(--aa)、calc()计算样式函数

热门文章

  1. React 组件封装之 Card 卡片
  2. hihoCoder 买零食
  3. JavaScript中6种继承方式总结
  4. iOS7初体验(1)——第一个应用程序HelloWorld
  5. 状态机练习(饮料贩卖机程序设计)8/9
  6. Cryptarithmetic Problem ‘ODD+ODD == EVEN’;map()函数,reduce()
  7. 旋转编码器(STM32)
  8. Lazadashopee热销产品有哪些?运动户外类目快速增长
  9. 字符串-Manacher算法(你知道马拉车算法吗?)
  10. 两台计算机直接相连教程,两台电脑怎么连接局域网,小编告诉你两台电脑怎么连接局域网...