POJ_1028
2010-04-13 16:52
453 查看
感觉是道基础题, 开始用栈实现的, 纠结了一阵子, 后来参考了网上的思路, 晕死...
#include <iostream> #include <string> using namespace std; const int MAX_NUM = 200; int main() { string command; string webSites[MAX_NUM] = {"http://www.acm.org/"}; int curIndex = 0; int webCount = 1; int back[MAX_NUM]; int forward[MAX_NUM]; int backIndex = 0, forwardIndex = 0; while(cin>>command && command != "QUIT") { if(command == "VISIT") { cin>>webSites[webCount]; back[backIndex++] = curIndex; curIndex = webCount; forwardIndex = 0; cout<<webSites[webCount++]<<endl; } else if(command == "BACK") { if(backIndex == 0) cout<<"Ignored"<<endl; else { forward[forwardIndex++] = curIndex; curIndex = back[--backIndex]; cout<<webSites[curIndex]<<endl; } } else if(command == "FORWARD") { if(forwardIndex == 0) cout<<"Ignored"<<endl; else { back[backIndex++] = curIndex; curIndex = forward[--forwardIndex]; cout<<webSites[curIndex]<<endl; } } } return 0; }
相关文章推荐
- POJ 1028-Web Navigation
- POJ 1028 Web Navigation
- POJ 1028
- POJ-1028-Web Navigation解题心得
- POJ 1028
- POJ 1028(简单的模拟浏览器)
- POJ 1028 小细节没处理好,没想好
- poj_1028 Web Navigation
- poj 1028 Web Navigation
- poj 1028 (STL)
- POJ-1028(字符串模拟)
- 母函数 整数拆分 (hdu 1028 , poj 1221)
- POJ 1028 Web Navigation(面向对象栈的封装)
- poj1028--动态规划--Ignatius and the Princess III
- POJ 1028
- poj 1028.Web Navigation
- Web Navigation - POJ 1028 栈
- POJ 1028
- 【stack】模拟网页浏览 poj 1028
- POJ1028 Web Navigation【堆栈+模拟】