Poj 1028

传送门

模拟网页浏览,设置两个栈,一个往前一个往后,浏览新的网页时清空往前的栈

 1 #include<iostream>
 2 #include<stack>
 3 using namespace std;
 4 
 5 int main(){
 6     stack<string> webback,webforward;
 7     webback.push("http://www.acm.org/");
 8     string cmd,url;
 9     while(cin>>cmd){
10         if(cmd[0]=='B'){//BACK
11             if(webback.size()==1){
12                 cout<<"Ignored"<<endl;
13             }
14             else{
15                 webforward.push(webback.top());
16                 webback.pop();
17                 cout<<webback.top()<<endl;
18             }
19         }
20         else if(cmd[0]=='F'){//FORWARD
21             if(webforward.empty()){
22                 cout<<"Ignored"<<endl;
23             }
24             else{
25                 webback.push(webforward.top());
26                 webforward.pop();
27                 cout<<webback.top()<<endl;
28             }
29         }
30         else if(cmd[0]=='V'){//VISIT
31             cin>>url;
32             while(!webforward.empty()){
33                 webforward.pop();
34             }
35             webback.push(url);
36             cout<<webback.top()<<endl;
37         }
38         else if(cmd[0]=='Q'){//QUIT
39             break;
40         }
41     }
42 } 

 

转载于:https://www.cnblogs.com/marlenemizuno/p/7216577.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值