您的位置:首页 > 其它

poj 1028 (STL)

2011-09-19 22:29 351 查看
题目链接: 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 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: