poj 1028 (STL)

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

    4、5个月前就做这题了,当时是用数组模拟的,结果RE到吐血!这次直接用STL模板,一次AC!文盲的悲哀啊!

 

#include<iostream>
#include
<fstream>
#include
<string>
#include
<stack>
using namespace std ;
int main(){
    stack
<string> a ;
    stack
<string> b ;           //b记录BACK操作前的页面
    string c ;
    a.push(
"http://www.acm.org/") ;
    
//fstream cin("x.in") ;
    while(cin>>c&&c!="QUIT"){
        
if(c=="VISIT"){
            cin 
>> c ;
            a.push(c) ;
            
while(!b.empty())   b.pop() ; //b不为空则将b清空
            cout << c << endl ;
        }
else
        
if(c=="BACK"){
            c 
= a.top() ;
            a.pop() ;
            
if(a.empty()){
                cout 
<< "Ignored" << endl ;
                a.push(c) ;
            }
            
else{
                cout 
<< a.top() << endl ;
                b.push(c) ;
            }
        }
else{
            
if(b.empty())   cout << "Ignored" << endl ;
            
else{
                cout 
<< b.top() << endl ;
                a.push(b.top()) ;
                b.pop() ;
            }
        }
    }
    
return 0 ;
}

 

 

原文地址:https://www.cnblogs.com/xiaolongchase/p/2181855.html