讨论 / 两个栈的C++
296293760 2017-11-11 07:41:36
点我顶贴 收藏 删除
#include<iostream>

#include<math.h>

#include<stack>

#include<queue>

#include<stdio.h>

using namespace std;

int main()

{

string temp;

stack<string> p,q;

p.push("http://www.acm.org/");

while(cin>>temp&&temp!="QUIT")

{

string display;

if(temp=="VISIT")

{

cin>>display;

p.push(display);

while(q.size()!=0)

q.pop();

cout<<p.top()<<endl;

}

else if(temp=="BACK"&&p.size()>1)

{

q.push(p.top());

p.pop();

cout<<p.top()<<endl;

}

else if(temp=="FORWARD"&&q.size()>0)

{

p.push(q.top());

q.pop();

cout<<p.top()<<endl;

}

else cout<<"Ignored"<<endl;

fflush(stdin);

}

return 0;

}

查看更多回复
提交回复