编程俱乐部每日一练(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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值