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 page

2.FORWARD:Go to the next page

3.VISIT URL:Access to the web page

Now,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

1.字符串函数 strcpy(a,b) 将字符串b赋给a
2. 当你去访问一个网站时,该网站后面的都会被抛弃

#include <stdio.h>
#include <string.h>
int main()
{
    char l[1009][109];
    char a[100];
    int n=0,m=0;
    char b[100];
    int i;
    strcpy(l[0],"http://www.acm.org/");
    while(scanf("%s",&a)!=EOF){
        if(a[0]=='Q'){
            break;
        }
        else if(a[0]=='V'){             
                n++;                            // n是索引值,后退则减,前进则加
                m++;                        //m代表列表长度
            scanf("%s",&l[m]);
            if(n<m){                       //当中途访问一个网站时,需将该网站插入当前位置,且这个位置以后的都被抛弃
            for(i=m;i>=n;i--){
            strcpy(l[i+1],l[i]);
            }
            strcpy(l[n],l[m+1]);
            m--;
            }
            printf("%s\n",l[n]);
        }
        else if(a[0]=='B'){
            if(n>0){
                n--;
                printf("%s\n",l[n]);
            }
            else if(n==0){

                printf("Ignored\n");
            }
        }
        else if(a[0]=='F'){
            if(n<m){
                    n++;
                printf("%s\n",l[n]);
            }
            else{
                printf("Ignored\n");
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43763889/article/details/84931959