- 229
- 0
- 约6.02千字
- 约 55页
- 2016-11-23 发布于湖北
- 举报
* * * * * * * * * * * * * * * * * * POJ 3250 :code #include iostream #include stack #include string using namespace std; int main() { string cmd, url; stackstring s1, s2; //定义了两个栈 //栈1用作存储操作队列,而栈2则用作临时保存栈1出栈的数据 s1.push(/); //首页压栈 while(cin cmd) { if(cmd == VISIT) //访问操作 { cin url; s1.push(url); //把访问的地址压入栈1 while(!s2.empty()) s2.pop(); //清空栈2 //想一想,为什么要清空栈2 cout s1.top() endl; } else if(cmd == BACK) //返回操作 { if(s1.size() 1) //如果此次弹出后不会使得栈变空 { s2.push(s1.top()); //把栈1顶元素压入栈2 s1.pop(); cout s1.top() endl; } else cout Ignored endl; } else if(cmd == FORWARD) //前进操作 { if(!s2.empty()) //栈2有
原创力文档

文档评论(0)