您的位置:首页 > 其它

poj 1028 Web Navigation

2013-07-28 20:02 357 查看
链接:点击打开链接

对栈的运用。

#include<iostream>
#include<stack>
#include<string>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
stack<string>forward,backward;
int i,j;
string s,current="http://www.acm.org/";
while(getline(cin,s)){
if(s=="QUIT")
break;
if(s.size()>7){
backward.push(current);
current=s.substr(6);
cout<<current<<endl;
while(!forward.empty())
forward.pop();
}
else if(s=="BACK"){
if(backward.empty())
cout<<"Ignored"<<endl;
else{
forward.push(current);
current=backward.top();
backward.pop();
cout<<current<<endl;
}
}
else if(s=="FORWARD"){
if(forward.empty())
cout<<"Ignored"<<endl;
else{
backward.push(current);
current=forward.top();
forward.pop();
cout<<current<<endl;
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: