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 ;
}
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 ;
}
相关文章推荐
- STL之stack——解决POJ 1028
- POJ 1028 Web Navigation 模拟,应用STL
- POJ-1028 Web Navigation(STL)
- POJ1028——Web Navigation
- POJ 1915 Knight Moves(BFS+STL)
- 【stack】模拟网页浏览 poj 1028
- POJ-1028 Web Navigation
- 模拟->YY POJ 1028 Web Navigation
- POJ 1028 Web Navigation
- 【POJ】1451 - T9(动态字典树 & dfs & STL)
- POJ 2418 Hardwood Species(STL在map应用)
- POJ 2049 Finding Nemo 优先队列 STL
- 【POJ】2061 - Subsequence(STL & 二分)
- 贪心(STL--set)--POJ 3067 Saruman's Army
- poj 3481 Double Queue 数据结构 STL
- hdoj 1028/poj 2704 Pascal's Travels(记忆化搜索||dp)
- poj2002 STL pair解法
- poj 1028 False coin
- POJ - 1338 Ugly Numbers-STL的灵活运用
- Poj 2431 Expedition【stl】