当前位置: 代码迷 >> 综合 >> POJ - 1028 Web Navigation(栈模拟)
  详细解决方案

POJ - 1028 Web Navigation(栈模拟)

热度:69   发布时间:2023-11-25 07:30:54.0

POJ - 1028 Web Navigation(栈模拟)

#include<iostream>
#include<stack>
using namespace std;
int main()
{
    stack<string> a,b;b.push("http://www.acm.org/");string s;while(cin>>s){
    if(s=="QUIT") break;if(s=="VISIT"){
    string str;cin>>str;cout<<str<<endl;b.push(str);while(!a.empty()) a.pop();}if(s=="BACK"){
    if(b.size()>1){
    a.push(b.top());b.pop();cout<<b.top()<<endl;}else cout<<"Ignored"<<endl;}if(s=="FORWARD"){
    if(a.size()>0){
    b.push(a.top());cout<<b.top()<<endl;a.pop();}else cout<<"Ignored"<<endl;}}return 0;
}
  相关解决方案