两会,咸宁核电:pascal题目求解

来源:百度文库 编辑:高考问答 时间:2024/04/28 02:39:34
Web浏览(web.pas)
实现浏览器的页面前后访问机制。有四种命令:
1、 BACK;
2、 FORWARD;
3、 VISIT:访问新的页面;
4、 QUIT:退出浏览器。
请参考实际的浏览器按钮的功能。
假设浏览器打开时,显示的页面是:http://www.acm.org/

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

输出:web.out
对于每一个命令(除了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

Program web;
Const
inf='web.in';
outf='web.out';
Var
hos:Array[1..1000] Of String;
i,curr,maxcur:Longint;
c,c1:char;
s:String;
Begin
Assign(input,inf);
Assign(output,outf);
Reset(input);Rewrite(output);
curr:=1;
hos[1]:='http://www.acm.org/';
While True Do Begin
Read(c);
Case c Of
'V': Begin
For i:=1 to 5 Do Read(c1);
Readln(s);
curr:=curr+1;
maxcur:=curr;
hos[curr]:=s;
Writeln(s);
End;
'B': Begin
Readln(s);
If curr>1 Then Begin
Dec(curr);
Writeln(hos[curr])
End Else Begin
Writeln('Ignored');
End;
End;
'F': Begin
Readln(s);
If curr<maxcur Then Begin
Inc(curr);
Writeln(hos[curr]);
End Else Begin
Writeln('Ignored');
End;
End;
'Q': Break;
End;
End;
Close(input);Close(output);
End.