ZOJ1061
2016-02-09 10:48
148 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=61
用容器stack,剩下的就是模拟了。
用容器stack,剩下的就是模拟了。
#include<iostream> #include<stack> #include<string> using namespace std; stack<string> Front; //前进栈 stack<string> Back; //后退栈 string URL; //当前页 void BACK(string order) { if (Back.empty()) { cout<<"Ignored"<<endl; return; } order = order.erase(0,4); Front.push(URL); URL = Back.top(); Back.pop(); cout<<URL<<endl; } void FORWARD(string order) { if (Front.empty()) { cout<<"Ignored"<<endl; return; } order = order.erase(0,7); Back.push(URL); URL = Front.top(); Front.pop(); cout<<URL<<endl; } void VISIT(string order) { order = order.erase(0,6); Back.push(URL); URL = order; cout<<URL<<endl; while (!Front.empty()) Front.pop(); } int main() { int N; cin>>N; while (N--) { string order; bool Exit = false; URL = "http://www.acm.org/"; while (getline(cin,order) && order!="QUIT") { switch (order[0]) { case 'B':BACK(order);break; case 'F':FORWARD(order);break; case 'V':VISIT(order);break; } } while (!Front.empty()) Front.pop(); while (!Back.empty()) Back.pop(); if (N) { cin.ignore(); cout<<endl; } } return 0; }
相关文章推荐
- xsl-fo图文混排的问题解决
- Aireplay-ng的6种攻击模式详解
- POJ3624(01背包:滚动 实现)
- android调用音乐播放器,三种方
- uva 11538 组合
- 志不强者智不达
- 深入理解Aireplay-ng各种攻击及其原理
- AJAX
- 智慧北京开发第三天(上)
- Matches正则使用提取内容
- Jquery库和自己定义库的区别
- C++自制Redis数据库(八)基本数据结构--String
- eclipse安装和使用
- auto-boxing, uboxing,以及缓存问题
- 第六届蓝桥杯C/C++B组第七题 牌型种数(回溯)
- SHUOJ 1552 滑雪(小数据)(BFS)
- 如何禁止App在后台运行以及如何保存和恢复App的状态
- 如何禁止App在后台运行以及如何保存和恢复App的状态
- 如何禁止App在后台运行以及如何保存和恢复App的状态
- ad15 的redefine board shape 在哪