题目:Web浏览

题目描述

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

输入格式

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

 

 

 

题解:

该题是看了别人的题解而成。要领会。。。。

代码实现:

View Code
 1 #include<iostream>
2 #include<cstring>
3 using namespace std;
4
5 string back[100],forw[100],now;
6 int top1=-1,top2=-1;
7
8 int main()
9 {
10 string a;
11 now="http://www.acm.org/";
12 cin>>a;
13 while(a!="QUIT")
14 {
15 if(a=="VISIT")
16 {
17 top2=-1;
18 top1++;
19 back[top1]=now;
20 cin>>now;
21 cout<<now<<endl;
22 }
23 if(a=="FORWARD")
24 {
25 if(top2>-1)
26 {
27 top1++;
28 back[top1]=now;
29 now=forw[top2];
30 top2--;
31 cout<<now<<endl;
32 }
33 else cout<<"Ignored"<<endl;
34 }
35 if(a=="BACK")
36 {
37 if(top1>-1)
38 {
39 top2++;
40 forw[top2]=now;
41 cout<<back[top1]<<endl;
42 now=back[top1];
43 top1--;
44 }
45 else cout<<"Ignored"<<endl;
46 }
47 cin>>a;
48 }
49 return 0;
50 }

 

转载于:https://www.cnblogs.com/noip/archive/2012/01/28/2330732.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值