您的位置:首页 > 其它

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;
}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  command string