#include<iostream>
#include<string>
#include<cstring>
#include<stack>
using namespace std;
stack <string> sta,temp;
char str[8]="VISTT";
int main()
{
sta.push("http://www.acm.org/");
string url;
while(1)
{
scanf("%s",str);
switch(str[0])
{
case 'Q':
return 0;
case 'V':
while(temp.size()) temp.pop();
cin>>url;
sta.push(url);
cout<<sta.top()<<endl;
break;
case 'B':
if(sta.size()>1)
{
temp.push(sta.top());
sta.pop();
cout<<sta.top()<<endl;
}else
printf("Ignored\n");
break;
case 'F':
if(temp.size()>0)
{
sta.push(temp.top());
temp.pop();
cout<<sta.top()<<endl;
}else
printf("Ignored\n");
break;
default: break;
}
}
return 0;
}
这个题:要注意的地方,也就是逻辑错误:
当VISIT时,你的FORWARD的栈要清空,因为要重新访问了一个网页。