题目: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.