POJ 1028 Web Navigation
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 30689 | Accepted: 13750 |
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
#include <iostream> #include <stdio.h> #include <string> #include <cstring> #include <cmath> #include <algorithm> #include <stack> #define N 109 using namespace std; char a[N]; string s="http://www.acm.org/"; int main() { stack<string>bac,fwd; while(~scanf("%s",a)) { if(a[0]=='Q') break; if(a[0]=='V') { bac.push(s); cin>>s; cout<<s<<endl; while(!fwd.empty()) fwd.pop(); } else if(a[0]=='B') { if(!bac.empty()) { fwd.push(s); s=bac.top(); bac.pop(); cout<<s<<endl; } else cout<<"Ignored"<<endl; } else if(a[0]=='F') { if(!fwd.empty()) { bac.push(s); s=fwd.top(); fwd.pop(); cout<<s<<endl; } else cout<<"Ignored"<<endl; } } return 0; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。