1. 程式人生 > >QAQ的小遊戲(18.12.7)

QAQ的小遊戲(18.12.7)

                              # QAQ的小遊戲     

Description

Recently,QAQ fell in love a small game,which simulates browser browsing web pages.It has three kind of operations:1.BACK: Back to the previous page2.FORWARD:Go to the next page3.VISIT URL:Access to the web pageNow,QAQ has visited http://www.acm.org/

, and wants to know the website after each operation, if the page not change, output “Ignored”.

Input

There is only one test data, and the number of operations does not exceed 1000,end flag when input "QUIT"Attion: every website length no more then 100.

Output

If the website changes, output the new website, if not, output Ignored.

Sample Input 1

VISIT http://oj.51ac.club/
VISIT http://maojunjie666.top/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT

Sample Output 1

http://oj.51ac.club/
http://maojunjie666.top/
http://oj.51ac.club/
http://www.acm.org/
Ignored
http://oj.51ac.club/
http://www.ibm.com/
http://oj.51ac.club/


http://www.acm.org/
http://oj.51ac.club/
http://www.ibm.com/
Ignored

這一題只需要注意如果直接進入下一個網頁的話後面所有的網頁都會更新就可以了,然後還需要用到一下字串相關函式。

程式碼:

#include<stdio.h>
#include<string.h>
int main()
{
    char a[1000][1000];
    char b[1000];
    int i,j;
    strcpy(a[0],"http://www.acm.org/");
    i=1;j=1;
    while(scanf("%s",b)!=EOF)
    {
        if(strcmp(b,"QUIT")==0)
            break;
        else if(strcmp(b,"VISIT")==0)
        {
            scanf("%s",b);
            strcpy(a[i],b);
            i++;j=i;  //j用來記錄最後網頁位置
            printf("%s\n",a[i-1]);
        }
        else if(strcmp(b,"BACK")==0)
        {
            if(i>1)
            {
                i--;
                printf("%s\n",a[i-1]);
            }
            else
                printf("Ignored\n");
        }
        else if(strcmp(b,"FORWARD")==0)
        {
            if(i<j)
            {
                i++;
                printf("%s\n",a[i-1]);
            }
            else
                printf("Ignored\n");

        }
    }
    return 0;
}