编程俱乐部每日一练(2018年12月7日)QAQ的小游戏

编程俱乐部每日一练(2018年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.

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


运用二维数组来储存链接,通过判断指令首字母来执行指令,VISIT则将链接存入数组并输出;BACK输出前一个数组,利用索引判断,若索引值小于0时,输出IGNORED;FORWARD类似于BACK,索引值大于上一个VISIT引入链接的索引值时,输出IGNORDED。
代码:

#include<stdio.h>
#include<string.h>
int main()
{
    char a[1001][101]={{"http://www.acm.org/"}};
    int c=0,d;
    char b[8];
    while(scanf("%s",&b)!=EOF){
        if(b[0]=='V'){
            c+=1;
            d=c;
            scanf("%s",&a[c]);
            printf("%s\n",a[c]);
        }
        else if(b[0]=='Q'){
            break;
        }
        else if(b[0]=='B'){
            if(c>=1){
                printf("%s\n",a[c-1]);
                c-=1;
            }
            else{
                printf("Ignored\n");
            }
        }
        else if(b[0]=='F'){
            if(c>=d){
                printf("Ignored\n");
            }
            else{
                printf("%s\n",a[c+1]);
                c+=1;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43763903/article/details/84973121
今日推荐