PUK 1028 WebNavigation

来源:互联网 发布:json 特殊字符 编辑:程序博客网 时间:2024/05/02 01:43

PUK    1028   模拟题

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

                        Web Navigatiopn


Time Limit: 1000MS Memory Limit: 10000KTotal 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/BACKBACKBACKFORWARDVISIT http://www.ibm.com/BACKBACKFORWARDFORWARDFORWARDQUIT

Sample Output

http://acm.ashland.edu/http://acm.baylor.edu/acmicpc/http://acm.ashland.edu/http://www.acm.org/Ignoredhttp://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;
}

/*
    后记:这种题目就是传说中的模拟题吧!感觉就是十分繁琐,弄的不好就会出错,第二次提交就错了!
*/


0 0