poj1028~无聊但是慢慢增加信心的水题_ios

超水的题目,题目中甚至都告诉你用2个栈来放网页,唯一要注意的就是VISIT操作后FORWARD操作将不再能执行,故要清空s2栈。

慢慢来吧,看着学校ACM群里的消息与自己已经没有关系后还是挺失落的,看看智能小车以后能不能再激发我的斗志了


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#define M 105
using namespace std;


struct stack
{
int top;
string web[M];
}s1,s2;


int main()
{
string com;
s1.top=s2.top=0;
s1.web[++s1.top]="http://www.acm.org/"; //主页
while(cin>>com)
{
if(com=="QUIT")
break;
else if(com=="VISIT")
{
cin>>com;
s1.web[++s1.top]=com; //放入s1栈,同时s2栈清零,因为只要更新了网页就无法再前进了
s2.top=0;
}
else if(com=="FORWARD")
{
if(s2.top!=0) //将s2中的网页放入s1中
{
com=s2.web[s2.top];
s1.web[++s1.top]=s2.web[s2.top];
s2.top--;
}
else com="Ignored";
}
else if(com=="BACK")
{
if(s1.top!=1) //将s1中的网页放入s2中,但是输出的是那个网页的前一个
{
s2.web[++s2.top]=s1.web[s1.top];
com=s1.web[--s1.top];
}
else com="Ignored";
}
cout<<com<<endl;
}
return 0;
}