zoukankan      html  css  js  c++  java
  • poj 1028 Web Navigation

    题目链接:http://poj.org/problem?id=1028

    解题思路:STL —— stack

      1 ///////////////////////////////////////////////////////////////////////////
      2 //problem_id: poj 1028
      3 //user_id: SCNU20102200088
      4 ///////////////////////////////////////////////////////////////////////////
      5 
      6 #include <algorithm>
      7 #include <iostream>
      8 #include <iterator>
      9 #include <iomanip>
     10 #include <cstring>
     11 #include <cstdlib>
     12 #include <string>
     13 #include <vector>
     14 #include <cstdio>
     15 #include <cctype>
     16 #include <cmath>
     17 #include <queue>
     18 #include <stack>
     19 #include <list>
     20 #include <set>
     21 #include <map>
     22 using namespace std;
     23 
     24 ///////////////////////////////////////////////////////////////////////////
     25 typedef long long LL;
     26 const double PI=acos(-1.0);
     27 ///////////////////////////////////////////////////////////////////////////
     28 
     29 ///////////////////////////////////////////////////////////////////////////
     30 //Add Code:
     31 ///////////////////////////////////////////////////////////////////////////
     32 
     33 int main(){
     34     ///////////////////////////////////////////////////////////////////////
     35     //Add code:
     36     string s,current;
     37     stack<string> forward,backward;
     38     current="http://www.acm.org/";
     39     while(cin>>s){
     40         if(s[0]=='B'){
     41             if(!backward.empty()){
     42                 forward.push(current);
     43                 current=backward.top();
     44                 backward.pop();
     45                 cout<<current<<endl;
     46             }
     47             else cout<<"Ignored"<<endl;
     48         }
     49         else if(s[0]=='F'){
     50             if(!forward.empty()){
     51                 backward.push(current);
     52                 current=forward.top();
     53                 forward.pop();
     54                 cout<<current<<endl;
     55             }
     56             else cout<<"Ignored"<<endl;
     57         }
     58         else if(s[0]=='V'){
     59             backward.push(current);
     60             cin>>current;
     61             cout<<current<<endl;
     62             while(!forward.empty()) forward.pop();
     63         }
     64         else if(s[0]=='Q') break;
     65     }
     66     ///////////////////////////////////////////////////////////////////////
     67     return 0;
     68 }
     69 
     70 ///////////////////////////////////////////////////////////////////////////
     71 /*
     72 Testcase:
     73 Input:
     74 VISIT http://acm.ashland.edu/
     75 VISIT http://acm.baylor.edu/acmicpc/
     76 BACK
     77 BACK
     78 BACK
     79 FORWARD
     80 VISIT http://www.ibm.com/
     81 BACK
     82 BACK
     83 FORWARD
     84 FORWARD
     85 FORWARD
     86 QUIT
     87 Output:
     88 http://acm.ashland.edu/
     89 http://acm.baylor.edu/acmicpc/
     90 http://acm.ashland.edu/
     91 http://www.acm.org/
     92 Ignored
     93 http://acm.ashland.edu/
     94 http://www.ibm.com/
     95 http://acm.ashland.edu/
     96 http://www.acm.org/
     97 http://acm.ashland.edu/
     98 http://www.ibm.com/
     99 Ignored
    100 */
    101 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    无线电,电磁波
    ThinkPHP实现支付宝接口功能
    php中发送email
    编程基本功训练:流程图画法及练习
    PHP中的特殊类,接口类和抽象类(都不能直接实例化)
    PHP中面相对象对象的知识点整理
    memcache 与 mencached扩展的区别
    MVC框架 与Smarty
    浏览器缓存机制
    PHP中九大缓存技术总结
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3261002.html
Copyright © 2011-2022 走看看