Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 27368 | Accepted: 12255 |
Description
The following commands need to be supported:
BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored.
FORWARD: Push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If the forward stack is empty, the command is ignored.
VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.
QUIT: Quit the browser.
Assume that the browser initially loads the web page at the URL http://www.acm.org/
Input
Output
Sample Input
VISIT http://acm.ashland.edu/ VISIT http://acm.baylor.edu/acmicpc/ BACK BACK BACK FORWARD VISIT http://www.ibm.com/ BACK BACK FORWARD FORWARD FORWARD QUIT
Sample Output
http://acm.ashland.edu/ http://acm.baylor.edu/acmicpc/ http://acm.ashland.edu/ http://www.acm.org/ Ignored http://acm.ashland.edu/ http://www.ibm.com/ http://acm.ashland.edu/ http://www.acm.org/ http://acm.ashland.edu/ http://www.ibm.com/ Ignored
Source
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main()
{
stack<string>a;
stack<string>b;
string dir,p;
dir="http://www.acm.org/";
a.push(dir);
while(cin>>dir){
if(dir=="QUIT") break;
if(dir=="VISIT"){
cin>>p;
cout<<p<<endl;
a.push(p);
while(!b.empty()) b.pop();
}else if(dir=="BACK"){
if(a.size()==1) cout<<"Ignored"<<endl;
else{
b.push(a.top());
a.pop();
cout<<a.top()<<endl;
}
}else if(dir=="FORWARD"){
if(!b.empty()){
cout<<b.top()<<endl;
a.push(b.top());
b.pop();
}else cout<<"Ignored"<<endl;
}
}
return 0;
}