码迷,mamicode.com
首页 > 其他好文 > 详细

toj 1196 栈的运用(模拟浏览器)

时间:2015-04-13 20:41:47      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

两个栈来模拟浏览器的操作,简单模拟。

 1 #include <iostream>
 2 #include <string>
 3 #include <stack>
 4 using namespace std;
 5 
 6 stack<string> forward;
 7 stack<string> back;
 8 
 9 int main ()
10 {
11     string cur("http://www.acm.org/"), tmp;
12     while ( cin >> tmp )
13     {
14         if ( tmp == "QUIT" )
15         {
16             break;
17         }
18         else if ( tmp == "BACK" )
19         {
20             if ( back.empty() )
21             {
22                 cout << "Ignored" << endl;
23             }
24             else
25             {
26                 forward.push(cur);
27                 cur = back.top();
28                 back.pop();
29                 cout << cur << endl;
30             }
31         }
32         else if ( tmp == "FORWARD" )
33         {
34             if ( forward.empty() )
35             {
36                 cout << "Ignored" << endl;
37             }
38             else
39             {
40                 back.push(cur);
41                 cur = forward.top();
42                 forward.pop();
43                 cout << cur << endl;
44             }
45         }
46         else if ( tmp == "VISIT" )
47         {
48             back.push(cur);
49             cin >> cur;
50             while ( !forward.empty() )
51             {
52                 forward.pop();
53             }
54             cout << cur << endl;
55         }
56     }
57     return 0;
58 }

toj 1196 栈的运用(模拟浏览器)

标签:

原文地址:http://www.cnblogs.com/huoxiayu/p/4423097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!