您的位置:首页 > 其它

ZOJ1061

2016-02-09 10:48 148 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=61

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