/*2018.8.28下午4点-2018.8.29 下午13:58
这题主要考察栈,本来用数组也能做,但是可能比较麻烦,加上我想练习一下栈
就用栈去写了
栈主要有这些操作
size、pop、push、top
就这些够用了
用两个栈去维护,当back或者forward的时候将一个栈里面的顶端给移到另一个栈的顶端
注意几个细节
1.back的那个栈最底层至少要有一个元素
2.forward在的那个栈是可以一个元素都没有的
3.考虑到现实意义,back的那个栈应该先pop再top输出而forward在的那个栈应该先top输出再pop
当然其实是一样的,我们可以考虑是全在back栈里面输出,就是forward先移到back然后再top输出
4.每次visit的时候,forward要清空。
*/
#include<stdio.h>
#include<string.h>
#include<stack>
#include <iostream>
using namespace std;
char p[100];
char a[100][100];
char v[100];
char back[100];
char forward[100];
char quit[100];
int main()
{
stack <string> b,f;
b.push("http://www.acm.org/");
int i=0;
while (1)
{
scanf("%s",p);
if (!strcmp(p,"VISIT"))
{
while (f.size()!=0)
f.pop();
i++;
scanf("%s",a[i]);
printf("%s\n",a[i]);
b.push(a[i]);
continue;
}
if (!strcmp(p,"BACK"))
{
if (b.size()==1)
{
printf("Ignored\n");
continue;
}
f.push(b.top());
b.pop();
cout<<b.top()<<endl;
i--;
}
if (!strcmp(p,"FORWARD"))
{
if (f.size()==0)
{
printf("Ignored\n");
continue;
}
cout<<f.top()<<endl;
b.push(f.top());
f.pop();
i++;
}
if (!strcmp(p,"QUIT"))
{
return 0;
}
}
}