【模拟】Web浏览

题目:Web浏览 rqnoj40

题目描述

实现浏览器的页面前后访问机制。有四种命令:
1、BACK;
2、FORWARD;
3、VISIT:访问新的页面;
4、QUIT:退出浏览器。
请参考实际的浏览器按钮的功能。
假设浏览器打开时,显示的页面是:http://www.acm.org/

输入格式

一系列命令:以BACK、FORWARD、VISIT或QUIT开头。如果是VISIT,后面要跟URL,长度不超过70,且不含空格。最后总是以QUIT结尾。

输出格式

对于每一个命令(除了QUIT),输出浏览页面的URL,如果命令被忽略,输出:Ignored。

样例输入

VISIT http://acm.ashland.edu/ VISIT http://asm.baylor.edu/acmipc/ BACK BACK BACK FORWARD VISIT http://www.ibm.com/ BACK BACK FORWARD FORWARD FORWARD QUIT

样例输出

http://acm.ashland.edu/ http://asm.baylor.edu/acmipc/ http://acm.ashland.edu/ http://www.acm.org/ Ignored http://acm.ashland.edu/ http://www.ibm.com/ http://acm.ashland.edu/ http://www.acm.org/ http://acm.ashland.edu/ http://www.ibm.com/ Ignored

 

题目没什么好说的,注意后退和前进的时候不要到无效地址就ok

pascal代码

 

program rqnoj40;

var
  a:array[1..1000000] of string;
  top,tt:longint;

procedure init;
begin
  assign(input,'rqnoj40.in');
  assign(output,'rqnoj40.out');
  reset(input);
  rewrite(output);
end;

procedure outit;
begin
  close(input);
  close(output);
  halt;
end;

procedure readdata;
var
  s,ss:string;
  i:longint;
begin
  a[1]:='http://www.acm.org/';
  top:=1;tt:=1;s:='';
  while true do
  begin
    readln(s);
    if s='QUIT' then outit
    else if s='BACK' then
    begin
      if top-1>0 then
      begin
        dec(top);
        writeln(a[top]);
      end
      else begin
        writeln('Ignored');
      end;
    end
    else if s='FORWARD' then
    begin
      if top+1<=tt then
      begin
        inc(top);
        writeln(a[top]);
      end
      else begin
        writeln('Ignored');
      end;
    end
    else begin//VISIT
      ss:=s;s:='';
      for i:=7 to length(ss) do s:=s+ss[i];
      inc(top);tt:=top;
      a[top]:=s;
      writeln(a[top]);
    end;
  end;
end;

procedure main;
begin
end;

begin
  init;
  readdata;
  main;
  outit;
end.

 

 

转载于:https://www.cnblogs.com/oijzh/archive/2012/08/17/2643540.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值