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 } 

 

posted @ 2017-07-21 10:55  水野玛琳  阅读(204)  评论(0编辑  收藏  举报