superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ZOJ 1061 - Web Navigation

Posted on 2008-03-27 22:28 superman 阅读(200) 评论(0)  编辑 收藏 引用 所属分类: ZOJ
 1 /* Accepted 1061 C++ 00:00.05 856K */
 2 #include <stack>
 3 #include <string>
 4 #include <iostream>
 5 
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int n;
11     cin >> n;
12     while(n--)
13     {
14         string command, url, curURL = "http://www.acm.org/";
15         stack<string> backward, forward;
16         
17         while(1)
18         {
19             cin >> command;
20             if(command == "QUIT")
21                 break;
22             if(command == "VISIT")
23             {
24                 backward.push(curURL);
25                 cin >> curURL;
26                 while(forward.empty() == false)
27                     forward.pop();
28             }
29             if(command == "BACK")
30             {
31                 if(backward.empty())
32                 {
33                     cout << "Ignored" << endl;
34                     continue;
35                 }
36                 else
37                 {
38                     forward.push(curURL);
39                     curURL = backward.top();
40                     backward.pop();
41                 }
42             }
43             if(command == "FORWARD")
44             {
45                 if(forward.empty())
46                 {
47                     cout << "Ignored" << endl;
48                     continue;
49                 }
50                 else
51                 {
52                     backward.push(curURL);
53                     curURL = forward.top();
54                     forward.pop();
55                 }
56             }
57             cout << curURL << endl;
58         }
59         if(n)
60             cout << endl;
61     }
62     
63     return 0;
64 }
65 

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理