Discover the Web(找浏览器网页)

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~dalao们点个关注呗~~


浏览器大家都不陌生咯~ 谷歌,搜狗,QQ,火狐,2345.....balabala的,这题可以类比哟yo~ (tips:谷歌浏览器右上角的一键网页翻译用来看英文题真的是比较6,虽然比赛的时候用不了........

Problem is coming~~~~

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. You are asked to implement this. The commands are:

1.      BACK: If the backward stack is empty, the command is ignored. Otherwise, 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.

2.      FORWARD: If the forward stack is empty, the command is ignored. Otherwise, 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.

3.      VISIT <url>: 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.

4.      QUIT: Quit the browser.

The browser initially loads the web page at the URL 'http://www.lightoj.com/'

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains some commands. The keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. URLs have no whitespace and have at most 50 characters. The end of case is indicated by the QUIT command and it shouldn't be processed. Each case contains at most 100 lines.

Output

For each case, print the case number first. For each command, print the URL of the current page (in a line) after the command is executed if the command is not ignored. Otherwise, print 'Ignored'.

Sample Input

1

VISIT http://uva.onlinejudge.org/

VISIT http://topcoder.com/

BACK

BACK

BACK

FORWARD

VISIT http://acm.sgu.ru/

BACK

BACK

FORWARD

FORWARD

FORWARD

QUIT

Sample Output

Case 1:

http://uva.onlinejudge.org/

http://topcoder.com/

http://uva.onlinejudge.org/

http://www.lightoj.com/

Ignored

http://uva.onlinejudge.org/

http://acm.sgu.ru/

http://uva.onlinejudge.org/

http://www.lightoj.com/

http://uva.onlinejudge.org/

http://acm.sgu.ru/

Ignored


哇,,,真的长,,,,还记得这是寒假训练的第一道题,到现在还能记得,那天凌晨的时候改了好久..光看题就看了好久emmm....感觉这个题其实可以当作浏览器左上角的那两个左右的小箭头,即向前向后翻页,还有转到XXX网站,他给的那个网址就可以看作是浏览器的首页。但是也有很多特殊情况要注意,比如最初就在主页的时候,如果是还转到这个网页的骚操作的话,再后退的情况。


----------------------------------------------------------------我只是一条可爱的分界线---------------------------------------------------------------


#include<stdio.h>
#include<string.h>
int main()
{
    int T,n,i,m;
    char a[60],s[201][101];
    scanf("%d",&n);
    for(T=1;T<=n;T++){
        m=0;i=0;
        strcpy(s[0],"http://www.lightoj.com/");
        printf("Case %d:\n",T);
        while(1){
            scanf("%s",a);
            if(a[0]=='Q')
                break;
            else if(a[0]=='V'){
                scanf("%s",a);
                strcpy(s[i+1],a);
                printf("%s\n",a);
                m=0;
            }
            else if(a[0]=='B'){
                if(i<=0){
                    printf("Ignored\n");
                    i--;
                }
                else{
                    m++;
                    puts(s[i-1]);
                    i-=2;
                }
            }
            else if(a[0]=='F'){
                if(!m){
                    printf("Ignored\n");
                    i--;
                }
                else{
                    puts(s[i+1]);
                    m--;
                }
            }
            i++;
        }
    }
    return 0;
}


欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~dalao们点个关注呗~~
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值